-
Notifications
You must be signed in to change notification settings - Fork 755
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 compiler crash when accessing previous parameter in default expression with lambda expression #41816
Fix compiler crash when accessing previous parameter in default expression with lambda expression #41816
Conversation
...r/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java
Outdated
Show resolved
Hide resolved
...lerina-unit-test/src/test/resources/test-src/functions/functions_with_default_parameters.bal
Outdated
Show resolved
Hide resolved
...lerina-unit-test/src/test/resources/test-src/functions/functions_with_default_parameters.bal
Outdated
Show resolved
Hide resolved
...lerina-unit-test/src/test/resources/test-src/functions/functions_with_default_parameters.bal
Show resolved
Hide resolved
…ina-lang into fix-41802 # Conflicts: # compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #41816 +/- ##
=============================================
+ Coverage 0.00% 76.56% +76.56%
- Complexity 0 53525 +53525
=============================================
Files 9 2905 +2896
Lines 35 202267 +202232
Branches 0 26336 +26336
=============================================
+ Hits 0 154858 +154858
- Misses 35 38924 +38889
- Partials 0 8485 +8485 ☔ View full report in Codecov by Sentry. |
if (function instanceof BallerinaFunctionSymbol && | ||
((BallerinaFunctionSymbol) function).getInternalSymbol().getOrigin() == SymbolOrigin.VIRTUAL) { | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come we didn't come across this previously?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping on this @chiranSachintha @dulajdilshan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously we haven't got any values such as this here to do the filtering. Let's better check why this is happening with the new changes.
However, it would be better to do the filtering in https://github.com/ballerina-platform/ballerina-lang/blob/master/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/LangLibrary.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue arises when using a parameter as the default value for another parameter without creating a new symbol for it. That is not correct. With this I have fixed that, and now we create a new symbol for that. So we need to skip those function as they are created in the desugar level.
Line 606 in 4d53eb7
BVarSymbol varSymbol = new BVarSymbol(Flags.REQUIRED_PARAM, symbolName, symbol.pkgID, type, funcSymbol, pos, |
@dulajdilshan We need to skip them within the filterLangLibMethods
. Isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we filter them in here:
ballerina-lang/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/LangLibrary.java
Line 179 in 9215217
private static void addLangLibMethods(String basicType, BPackageSymbol langLibModule, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
...lerina-unit-test/src/test/resources/test-src/functions/functions_with_default_parameters.bal
Outdated
Show resolved
Hide resolved
...lerina-unit-test/src/test/resources/test-src/functions/functions_with_default_parameters.bal
Outdated
Show resolved
Hide resolved
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/CompilerUtils.java
Outdated
Show resolved
Hide resolved
varSymbol.owner == resolvedSymbolEnv.scope.owner) { | ||
if (entry != NOT_FOUND_ENTRY && varSymbol == entry.symbol) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this because we don't shadow the symbol like we discussed offline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, when looking for the resolved level of a symbol, we don't need to check for the symbol owner. If there's the same symbol with two different owners, it becomes a compile-time error. I believe we introduced this logic before addressing the shadowing issue(that is the reason to add this check).
The reason for keeping the varSymbol == entry.symbol
logic is because there are instances in the desugar where we use the same symbol generate variable. However, this is also not correct, and we need to address it separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we created an issue for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
Closed PR due to inactivity for more than 18 days. |
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
457647e
to
4d53eb7
Compare
varSymbol.owner == resolvedSymbolEnv.scope.owner) { | ||
if (entry != NOT_FOUND_ENTRY && varSymbol == entry.symbol) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we created an issue for this?
varSymbol.flags = 0; | ||
funcSymbol.scope.define(varSymbol.name, varSymbol); | ||
BType type = symbol.type; | ||
Location pos = funcSymbol.pos; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed, so extract to a variable outside the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the position right? Type is extract from the parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
...lerina-unit-test/src/test/resources/test-src/functions/functions_with_default_parameters.bal
Outdated
Show resolved
Hide resolved
...lerina-unit-test/src/test/resources/test-src/functions/functions_with_default_parameters.bal
Outdated
Show resolved
Hide resolved
00d515d
to
b863355
Compare
...lerina-unit-test/src/test/resources/test-src/functions/functions_with_default_parameters.bal
Outdated
Show resolved
Hide resolved
...lerina-unit-test/src/test/resources/test-src/functions/functions_with_default_parameters.bal
Outdated
Show resolved
Hide resolved
return a + b(); | ||
} | ||
|
||
function testParamUseAsValueInAnonFuncWithDefaultForNextParam() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function testParamUseAsValueInAnonFuncWithDefaultForNextParam() { | |
function testUsingParamInAnonFuncDefaultValueOfSubsequentParam() { |
}) returns int { | ||
return a + b(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add at least one test
- where it's not the next immediate param that accesses a previous param like this
- with an expression-bodied function as the default value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests with ce41d41
@chiranSachintha, please check the level 6 build failure. |
Purpose
Fixes #41802
Check List