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

Incorrect static type of member-access-expr when the static type of container-expression is a subtype of xml<M> #35019

Closed
lasinicl opened this issue Feb 10, 2022 · 2 comments · Fixed by #43421
Assignees
Labels
Area/TypeChecker Type Checker related issues #Compiler Error/TypeK correct program, gets "this program is wrong" error at compile time Lang/XML XML related issues Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug
Milestone

Comments

@lasinicl
Copy link
Contributor

lasinicl commented Feb 10, 2022

Description:
$title
The spec (https://ballerina.io/spec/lang/master/#member-access-expr) says,

Let T the static type of container-expression. ......
If T is a subtype of xml<M>, then the static type of the member-access-expr is M|E, where E is the type of the empty xml value.

Steps to reproduce:

type XmlType1 xml<xml:Element|xml:ProcessingInstruction>;

function init() {
    xml a1 = xml `<name>Sherlock Holmes</name><!--Comment-->`;
    xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text b1 = a1[0]; // OK

    xml<xml:Comment> a2 = xml `<!--Comment1--><!--Comment2-->`;
    xml:Comment b2 = a2[1]; // incompatible types: expected 'xml:Comment', found 'xml<xml:Comment>'

    xml<xml:ProcessingInstruction> a3 = xml `<?xml-stylesheet type="text/xsl" href="style.xsl"?>`;
    xml:ProcessingInstruction b3 = a3[0]; // incompatible types: expected 'xml:ProcessingInstruction', found 'xml<xml:ProcessingInstruction>'

    xml<xml:Element> a4 = xml `<name>Sherlock Holmes</name><name>Enid Blyton</name>`;
    xml:Element b4 = a4[1]; // incompatible types: expected 'xml:Element', found 'xml<xml:Element>'

    xml<xml:Text> a5 = xml `Some Text`;
    xml:Text b5 = a5[0]; // OK
    xml<xml:Text> b6 = a5[0]; // OK

    XmlType1 a6 = xml `<name>Enid Blyton</name><name>Dan Brown</name>`;
    xml:Element|xml:ProcessingInstruction b7 = a6[1]; // incompatible types: expected '(xml:Element|xml:ProcessingInstruction)', found 'xml<(xml:Element|xml:ProcessingInstruction)>'
}

Affected Versions:
Ballerina 2201.0.0 (Swan Lake)

@lasinicl lasinicl added Type/Bug Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Area/TypeChecker Type Checker related issues #Compiler Error/TypeK correct program, gets "this program is wrong" error at compile time and removed Area/TypeChecker Type Checker related issues #Compiler labels Feb 10, 2022
@MaryamZi
Copy link
Member

See ballerina-platform/ballerina-spec#727 (comment)

The current types are incorrect, but the actual type may have to include xml<never>.

@MaryamZi MaryamZi self-assigned this Apr 1, 2024
@MaryamZi MaryamZi added the Lang/XML XML related issues label Aug 30, 2024
@MaryamZi
Copy link
Member

I've implemented the changes to fix the static type, but the change may result in langlib functions being called on xml unions now, in places that were previously a langlib call on a value of the xml type.

E.g.,

xml<xml:Comment> a = xml ``;
int length = a[0].length();

But, xml langlib functions aren't supported on unions yet - #28697. Putting this issue on hold to see if we can fix that since if not, this could be a backward incompatible change.

@MaryamZi MaryamZi added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Sep 26, 2024
@MaryamZi MaryamZi added this to the 2201.11.0 milestone Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/TypeChecker Type Checker related issues #Compiler Error/TypeK correct program, gets "this program is wrong" error at compile time Lang/XML XML related issues Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants