-
Notifications
You must be signed in to change notification settings - Fork 744
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
Add support for record literals with mapping binding patterns and fix using mapping-binding pattern within a list binding pattern against an open record #40283
Conversation
Please update the title to reflect what's actually being fixed. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #40283 +/- ##
============================================
- Coverage 77.35% 77.33% -0.03%
- Complexity 58436 58545 +109
============================================
Files 3454 3460 +6
Lines 219598 219990 +392
Branches 28870 28914 +44
============================================
+ Hits 169880 170136 +256
- Misses 40330 40449 +119
- Partials 9388 9405 +17 ☔ View full report in Codecov by Sentry. |
...erina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java
Outdated
Show resolved
Hide resolved
...erina-unit-test/src/test/resources/test-src/expressions/varref/record-variable-reference.bal
Outdated
Show resolved
Hide resolved
...erina-unit-test/src/test/resources/test-src/expressions/varref/record-variable-reference.bal
Outdated
Show resolved
Hide resolved
...erina-unit-test/src/test/resources/test-src/expressions/varref/record-variable-reference.bal
Outdated
Show resolved
Hide resolved
...erina-unit-test/src/test/resources/test-src/expressions/varref/record-variable-reference.bal
Outdated
Show resolved
Hide resolved
...erina-unit-test/src/test/resources/test-src/expressions/varref/record-variable-reference.bal
Outdated
Show resolved
Hide resolved
...erina-unit-test/src/test/resources/test-src/expressions/varref/record-variable-reference.bal
Outdated
Show resolved
Hide resolved
...erina-unit-test/src/test/resources/test-src/expressions/varref/record-variable-reference.bal
Outdated
Show resolved
Hide resolved
...erina-unit-test/src/test/resources/test-src/expressions/varref/record-variable-reference.bal
Outdated
Show resolved
Hide resolved
...erina-unit-test/src/test/resources/test-src/expressions/varref/record-variable-reference.bal
Outdated
Show resolved
Hide resolved
...erina-unit-test/src/test/resources/test-src/expressions/varref/record-variable-reference.bal
Outdated
Show resolved
Hide resolved
...erina-unit-test/src/test/resources/test-src/expressions/varref/record-variable-reference.bal
Outdated
Show resolved
Hide resolved
Experiencing an NPE in ballerina runtime for the following
Working on fixing it |
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
This scenario seems to be fixe via #37184 |
Had a chat with @MaryamZi and @chiranSachintha. It seems this scenario needs to be disallowed |
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. |
Please fix the build/test failures. |
name: fName, | ||
age, | ||
married, | ||
...theMap |
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.
theMap isn't asserted
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.
That's intentional. We don't need to assert it. We have asserted it in the other tests.
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.
we can remove this test. It seems this test is not necessary.
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.
That's intentional. We don't need to assert it. We have asserted it in the other tests.
Why can't we just assert it? We either need to assert it or remove that binding.
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.
Fixed via 6568a25
Still not supported with typed binding patterns so I would update the title and add a comment on #19804 saying this is only enabled for destructuring assignments in this PR. Ideally, it should be straightforward to support the same with typed binding patterns too. |
@@ -2199,11 +2199,6 @@ public void visit(BLangSimpleVariableDef varDefNode, AnalyzerData data) { | |||
|
|||
@Override | |||
public void visit(BLangRecordVariableDef varDefNode, AnalyzerData data) { | |||
// TODO: 10/18/18 Need to support record literals as well | |||
if (varDefNode.var.expr != null && varDefNode.var.expr.getKind() == RECORD_LITERAL_EXPR) { | |||
dlog.error(varDefNode.pos, DiagnosticErrorCode.INVALID_LITERAL_FOR_TYPE, "record binding pattern"); |
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.
Why isn't this DiagnosticErrorCode removed?
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.
Removed via 08f5e57c
@@ -2199,11 +2199,6 @@ public void visit(BLangSimpleVariableDef varDefNode, AnalyzerData data) { | |||
|
|||
@Override | |||
public void visit(BLangRecordVariableDef varDefNode, AnalyzerData data) { | |||
// TODO: 10/18/18 Need to support record literals as well | |||
if (varDefNode.var.expr != null && varDefNode.var.expr.getKind() == RECORD_LITERAL_EXPR) { | |||
dlog.error(varDefNode.pos, DiagnosticErrorCode.INVALID_LITERAL_FOR_TYPE, "record binding pattern"); |
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.
Where have the tests been added 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.
Noticed that they've been added in RecordVariableReferenceTest.java. That's not the correct class. Should go in RecordVariableDefinitionTest.
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.
Ack
|
||
var {country, ...rest} = {country: "USA", zipCode: 80001}; | ||
assertEquality("USA", country); | ||
assertEquality({zipCode: 80001}, rest); |
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 more tests including where the member binding patterns are in turn structured binding patterns.
Also add negative tests for unspecified fields, optional field binding, etc.
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.
@dulajdilshan can you please point to the negative tests?
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.
Added in edebb78
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.
Title needs to be changed too.
assertEquality("Alabama", state); | ||
assertEquality(35004, postalCode); | ||
|
||
record {|string street; float...;|} {street, ...coordinates} = {street: "Highway 61", "lat": 37.30, "lon": -90.40}; |
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.
Also add for when some of the required fields are bound as rest.
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.
Added in edebb78
int b; | ||
int c; | ||
[{a, b}]= l1; | ||
[int, [record {int b?;}]] l2= [1, [{b: 1}]]; |
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.
[int, [record {int b?;}]] l2= [1, [{b: 1}]]; | |
[int, [record {int b?;}]] l2 = [1, [{b: 1}]]; |
Fix everywhere.
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.
Addressed via 3de0d3e
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.
Use underscores for file names.
Also proper terms for new files/code - e.g., record_bp_in_list_bp_destructuring_assignment_negative.bal
1caf979
into
ballerina-platform:master
Purpose
$title
Fixes #39324
Fixes #19804
Original PR: #40113 (invalidated)
Approach
Samples
Remarks
Encountered the following issue
NoSuchMethodError
exception when running with tuple destructure #41174Check List