Skip to content

[Bug]: False positive return-check error when using match case accessing a JSON field #44424

Description

@mahimadesilva

Description

When using a match expression on a JSON field inside a do { } on fail block, and each match case performs a return, the Ballerina compiler reports:

ERROR [main.bal:(134:1,134:2)] this function must return a result

This issue occurs even when a wildcard (_) case is included.

Steps to Reproduce

Reproducible Code:

public function doEval(json selectExpression) returns string|error {
    do {
        match selectExpression.key1 {
            "column" =>
            {
                return "c";
            }
            "select" =>
            {
                return "s";
            }
            _ =>
            {
                return "d";
            }

        }
    } on fail error err {
        return err;
    }
}

Affected Version(s)

Ballerina 2201.12.10 (Swan Lake Update 12)

OS, DB, other environment details and versions

Windows 10

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions