Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Incorrectly desugaring when using "Do on-fail" within Query Action #42632

Open
chiranSachintha opened this issue Apr 25, 2024 · 0 comments
Assignees
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation

Comments

@chiranSachintha
Copy link
Member

Description

Consider the following example

function f1() {
    from int i in [1, 2, 3]
    do {
        do {
        } on fail error e {
            error res2 = e;
        }
    };
}

We desugared the above program into the following form

BLangFunction: [] testCatchingErrorAtOnFail ([]) (null) Body: {[int] $streamElement$_0 = <[int]> [1]; ballerina/lang.query:0.0.0:_StreamPipeline $streamElement$_1 = [int] $collection$1 = $streamElement$_0; typedesc<error?> $constraintTd$2 = error?; typedesc<error?> $completionTd$3 = error?; boolean $isLazyLoading$4 = false; ballerina/lang.query:0.0.0:_StreamFunction $streamElement$_2 = function (ballerina/lang.query:0.0.0:_Frame) returns ((ballerina/lang.query:0.0.0:_Frame|error)?) $inputFunc$5 = LambdaRef:$streamLambda$_0; ballerina/lang.query:0.0.0:_StreamPipeline $pipeline$6 = $streamElement$_1; ballerina/lang.query:0.0.0:_StreamFunction $streamFunction$7 = $streamElement$_2; ballerina/lang.query:0.0.0:_StreamFunction $streamElement$_3 = function (ballerina/lang.query:0.0.0:_Frame) returns ((any|error)) $doFunc$8 = LambdaRef:$streamLambda$_1; ballerina/lang.query:0.0.0:_StreamPipeline $pipeline$9 = $streamElement$_1; ballerina/lang.query:0.0.0:_StreamFunction $streamFunction$10 = $streamElement$_3; stream<ballerina/lang.query:0.0.0:Type,ballerina/lang.query:0.0.0:CompletionType> $streamElement$_4 = ballerina/lang.query:0.0.0:_StreamPipeline $pipeline$11 = $streamElement$_1; (any|error) $streamElement$_5 = stream<ballerina/lang.query:0.0.0:Type,ballerina/lang.query:0.0.0:CompletionType> $strm$12 = $streamElement$_4; if ($streamElement$_5 is ballerina/lang.query:0.0.0:QueryErrorTypes) $streamElement$_5 = <(any|error)> <error> error $err$13 = <error> $streamElement$_5; Return: ()}

BLangFunction: [LAMBDA, QUERY_LAMBDA] $streamLambda$_0 ([ballerina/lang.query:0.0.0:_Frame $frame$]) (record { [] }|error|null) Body: {int i = <int> $frame$[value]; $frame$[i] = <(any|error)> i; Return: $frame$}

BLangFunction: [LAMBDA, QUERY_LAMBDA] $streamLambda$_1 ([ballerina/lang.query:0.0.0:_Frame $frame$]) (any|error) Body: {error e = <error> $frame$[e]; ; Return: ()}

When look at the desugared code we try to access error from the frame and then assign it to error e.

That is not correct. The reason is in the above example

When examining the desugared code, we attempt to access an error from the frame and assign it to error e. However, this approach is incorrect.

on fail error e {
     error res2 = e;
}

The reason for that is, in the example "on-fail" clause is part of the "do" block within the query action. As a result, it has no connection to the error and the query action.

Steps to Reproduce

No response

Affected Version(s)

No response

OS, DB, other environment details and versions

No response

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@chiranSachintha chiranSachintha added Type/Bug Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. labels Apr 25, 2024
@chiranSachintha chiranSachintha self-assigned this Apr 25, 2024
@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Apr 25, 2024
@chiranSachintha chiranSachintha removed the needTriage The issue has to be inspected and labeled manually label Apr 25, 2024
@chiranSachintha chiranSachintha moved this from In Progress to PR Sent in Ballerina Team Main Board Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation
Projects
Status: PR Sent
Development

Successfully merging a pull request may close this issue.

2 participants