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

Fix bad sad error in SemanticAnalyzer #42796

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,8 @@ private void handleDeclaredWithVar(BLangVariable variable, AnalyzerData data) {
handleWildCardBindingVariable(simpleVariable, currentEnv);

long ownerSymTag = currentEnv.scope.owner.tag;
if ((ownerSymTag & SymTag.INVOKABLE) == SymTag.INVOKABLE || (ownerSymTag & SymTag.LET) == SymTag.LET) {
if ((ownerSymTag & SymTag.INVOKABLE) == SymTag.INVOKABLE || (ownerSymTag & SymTag.LET) == SymTag.LET ||
(ownerSymTag & SymTag.PACKAGE) == SymTag.PACKAGE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the variable is in the package scope, we define those variables in the symbol enter. Here, what we define are variables within functions, and the variables' owner becomes let. In the following scenario, the owner tag should also be equal to let.

In the current implementation, we set the owner as package instead of let. This is the root cause of the issue.

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

Student[] students = [];

var v1 = from var st in students
    let var name = st.fname + st.lname
    select name;

function testModuleLevelLetClause() {
    var v2 = from var st in students
        let var name = st.fname + st.lname
        select name;
}

// This is a variable declared in a function, an action or a resource
// If the variable is parameter then the variable symbol is already defined
if (simpleVariable.symbol == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ public Object[] dataToTestGroupByClauseWithListCtr() {
"testGroupbyVarDefsAndSelectWithGroupingKeysFromClause1",
"testGroupByVarDefsAndSelectWithGroupingKeysWithJoinClause1",
"testGroupByVarDefsAndSelectWithGroupingKeysWithJoinClause2",
"testGroupByVarAndSelectWithNonGroupingKeysWithJoinClause1"
"testGroupByVarAndSelectWithNonGroupingKeysWithJoinClause1",
"testModuleLevelGroupBy"
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public Object[] getFuncNames() {
"testwildcardBindingPatternInLetClause",
"testQueryInLetClauseAsAClosure1",
"testQueryInLetClauseAsAClosure2",
"testQueryInLetClauseAsAClosure3"
"testQueryInLetClauseAsAClosure3",
"testModuleLevelLetClause"
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,25 @@ function assertEquality(anydata expected, anydata actual) {
panic error("expected '" + expected.toString() + "', found '" + actual.toString() + "'");
}

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

Person[] person = [];

var v1 = from var st in person
group by var name = st.fname + st.lname
select name;

function testModuleLevelGroupBy() {
var v2 = from var st in person
group by var name = st.fname + st.lname
select name;
var v3 = v1;
}

// TODO: Add test cases readonly types
// TODO: use a client
// TODO: xml langlib function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,21 @@ function assertEquality(any|error expected, any|error actual) {
panic error(ASSERTION_ERROR_REASON,
message = "expected '" + expectedValAsString + "', found '" + actualValAsString + "'");
}

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

Student[] students = [];

var v1 = from var st in students
let var name = st.fname + st.lname
select name;

function testModuleLevelLetClause() {
var v2 = from var st in students
let var name = st.fname + st.lname
select name;
}
Loading