-
Notifications
You must be signed in to change notification settings - Fork 753
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 invalid subtyping relationship in xml #42221
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #42221 +/- ##
============================================
- Coverage 77.55% 77.48% -0.08%
+ Complexity 58752 58448 -304
============================================
Files 3448 3432 -16
Lines 219728 218416 -1312
Branches 28922 28870 -52
============================================
- Hits 170411 169234 -1177
+ Misses 39921 39804 -117
+ Partials 9396 9378 -18 ☔ View full report in Codecov by Sentry. |
if (types.isAssignable(varType, typeNodeType)) { | ||
if (types.constituentTypesAssignable(varType, typeNodeType)) { |
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 are we changing these? isAssignable should produce correct results.
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 a special case. With the modification to isAssignable
function in this PR, variable with static type of xml
is not assignable to xml<xml:Element>|xml<xml:Comment>|xml<xml:ProcessingInstruction>|xml:Text
or xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text
(Which is the correct behaviour and which is expected).
The function given here is used to validate the types in a foreach loop. In a foreach loop context, variable with static type xml
is assignable to loop variable of type xml<xml:Element>|xml<xml:Comment>|xml<xml:ProcessingInstruction>|xml:Text
. Thus here it is not possible to use isAssignable
Example code,
function foo() {
xml x = xml `<a></a><!--comment-->text<?data?>`;
foreach xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text item in x {
}
}
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 function given here is used to validate the types in a foreach loop. In a foreach loop context, variable with static type
xml
is assignable to loop variable of typexml<xml:Element>|xml<xml:Comment>|xml<xml:ProcessingInstruction>|xml:Text
. Thus here it is not possible to useisAssignable
This definition isn't entirely correct, is it? In the loop/foreach case we should be checking the sequence member type (xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text
) against the foreach variable type, not xml.
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.
Right, yes. But we cannot isAssignable
for this check right, since for variable with static type xml
it can't be assigned to xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text
.
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.
What I meant was that we should be using isAssignable
with
- source type -
xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text
against - target type -
xml<xml:Element>|xml<xml:Comment>|xml<xml:ProcessingInstruction>|xml:Text
which will (should) evaluate to true.
xml
is xml<xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text>
, therefore, iteration value type is xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text
. https://ballerina.io/spec/lang/master/#section_5.1.6
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.
In the case of type parameter the assignability is checked using the isAssignable(sourceParam, targetParam)
In the case of xml we cannot use this check.
Consider the following code
xml x = xml `<a>a</a>`;
x.forEach(function (xml entry) {
});
Here the targetType is xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text
and the source type is xml
. Since an xml value cannot be assigned to ``xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text` the check for xml is made special case for type params in this commit
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 |
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 |
...r/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java
Outdated
Show resolved
Hide resolved
...r/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java
Outdated
Show resolved
Hide resolved
...r/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java
Show resolved
Hide resolved
...allerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/SymbolTable.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 |
7182d77
to
fefd6ed
Compare
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
5058212
to
c72f3db
Compare
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 |
621db18
to
310444d
Compare
...action/create-variable/config-rename-positional-capability/createVariableInQueryAction3.json
Show resolved
Hide resolved
.../jballerina-unit-test/src/test/java/org/ballerinalang/test/query/XMLQueryExpressionTest.java
Show resolved
Hide resolved
a41fc4a
to
3db666f
Compare
3db666f
to
04cb468
Compare
Purpose
Fixes #34779
Approach
Update
isAssignable
to not to allow assigning of value with static typexml
to value with static typexml:Comment|xml:Element|xml:ProcessingInstruction|xml:Text
. But this assignment is allowed in the type binding pattern in theforeach
loops. Thus in order to handle this case new function is introducedconstituentTypesAssignable
.Samples
Remarks
Check List