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]: Runtime variable and line number tables are generated incorrectly for binding pattern variables #43623

Open
NipunaRanasinghe opened this issue Nov 20, 2024 · 2 comments
Assignees
Labels
Priority/Blocker Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug

Comments

@NipunaRanasinghe
Copy link
Contributor

NipunaRanasinghe commented Nov 20, 2024

Description

$subject.

Related to #42411.

Steps to Reproduce

Use the below sample code and add a debug breakpoint point last line of the main() function

type Person record {|
    int id;
    string fname;
    string lname;
|};

type SampleErrorData record {|
    int code;
    string reason;
|};

type SampleError error<SampleErrorData>;

public function main() {

    // simple binding pattern
    var profession = "Software Engineer";

    // list binding pattern
    [int, [string, string]] [id, [firstName, _]] = getDetails();

    // mapping binding pattern
    string givenName;
    string surname;
    {fname: givenName, lname: surname} = getPerson();

    // error binding pattern
    var error(_, cause, code = code, reason = reason) = getSampleError();

    // binding patterns inside a match statement
    matchCommand(["Remove", "*", true]);
}

function getDetails() returns [int, [string, string]] {
    return [
        1234,
        ["John", "Doe"]
    ];
}

function getPerson() returns Person {
    Person person = {id: 1001, fname: "Anne", lname: "Frank"};
    return person;
}

function getSampleError() returns SampleError {
    return error("Transaction Failure", error("Database Error"), code = 20, reason = "deadlock condition");
}

function matchCommand(any commands) {
    match commands {
        var [show] => {
            string name = "show";
        }
        // The list binding pattern below binds lists that contain three list items
        // where the third element in the list is the boolean value `true`.
        var [remove, all, isDir] if isDir is true => {
            string name = "remove";
        }
        // The list binding pattern below binds lists that contain three list items.
        var [remove, all, _] => {
            string name = "remove";
        }
        // The list binding pattern below binds lists that contain two list items,
        // in which the second list item is also a list of two items.
        var [copy, [file1, file2]] => {
            string name = "copy";
        }
        _ => {
            string name = "unknown";
        }
    }
}
  1. When the debug point gets hit, observe the visible local variables. No binding pattern variables are visible to the location.

Affected Version(s)

2201.10.x and below

OS, DB, other environment details and versions

No response

Related area

-> Runtime

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@warunalakshitha
Copy link
Contributor

Type binding variables ( ex. id, firstname, givenName, surName in main method) are inside BlangBlockStatement. So when we generating scopes for the bir, scope is set only to given block. So when generating target bytecode, Line numbers are restricted to given block line numbers only.

When we generating BIR, we do not have a way to seperate out type binding variables with other scope variables. (Ex. inside if). This might needs to be handle in AST generation. @gimantha @MaryamZi

@MaryamZi
Copy link
Member

Seems to work for the error binding pattern, so may be possible for the other two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority/Blocker Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug
Projects
Status: In Progress
Development

No branches or pull requests

5 participants