-
Notifications
You must be signed in to change notification settings - Fork 758
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
Improve the error message for invalid table key values #41992
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #41992 +/- ##
============================================
- Coverage 76.71% 76.70% -0.01%
- Complexity 53062 53080 +18
============================================
Files 2882 2882
Lines 200002 200031 +29
Branches 26040 26048 +8
============================================
+ Hits 153423 153443 +20
- Misses 38132 38137 +5
- Partials 8447 8451 +4 ☔ View full report in Codecov by Sentry. |
...erina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java
Show resolved
Hide resolved
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 |
e9423ff
into
ballerina-platform:master
Purpose
The current implementation of checking whether the table key value is a constant expression does not consider its nested expressions. Thus, this PR improves the implementation to precisely capture the
value expression of key specifier 'k' must be a constant expression
error message.As mentioned in the specification, a constant-reference expression must reference a module-const-decl, and within a const-expr, any nested expression must also be a const-expr. The existing positive table key field value tests do not adhere to this condition, and this PR updates those test cases with the necessary changes. https://ballerina.io/spec/lang/master/#const-expr
Fixes #35043
Approach
The PR modifies the TypeChecker to improve its implementation of checking the constant expression for table key values.
Remarks
isConstExpression
that is specific to the table itself. Hence, the changes made by the PR only affect this area. Ideally, this method can be used in other areas as well, and this is tracked with another issue:list constructor spread operator
as it is blocked by: [Bug]: An invalid error is generated when using a constant expression in a spread operator #41979xml templates
as it is blocked by: [Improvement]: Improve the error reporting of XML templates when used as key values in tables #41985regex templates
it is blocked by: [Improvement]: Improve the error reporting of Regex templates when used as key values in tables #41982Check List