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

[Bug]: When inferring type for query-exp, collections of types other than query construct types should throw an error #37670

Closed
pcnfernando opened this issue Sep 7, 2022 · 6 comments · Fixed by #37547 or #41117
Assignees
Labels
Priority/Blocker Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug Type/SpecDeviation

Comments

@pcnfernando
Copy link
Member

Description

From the spec https://ballerina.io/spec/lang/master/#section_6.35:

If there is no contextually expected type, then the basic type of the value constructed is the basic type of expression following in; it is a compile-time error if the static type of this expression is not a subtype of one of the basic types that a query expression can construct.

import ballerina/io;
public function main() {
    xml x = xml ``;
    var res = from xml i in x // we should get an error here incompatible types: 'xml' cannot be constrained with 'int'
    select 1;

    io:println(res is int[]); //error incompatible types: 'xml<int>' will not be matched to 'int[]'
}
public function main() {
    var res = from string i in "x"
    select 1; // atm, no errors. should be an error

    string x = res;
}

Steps to Reproduce

No response

Affected Version(s)

2201.2.0

OS, DB, other environment details and versions

No response

Labels

CompilerFE

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@pcnfernando pcnfernando added Type/Bug Type/SpecDeviation Priority/Blocker Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. labels Sep 7, 2022
@SasinduDilshara
Copy link
Contributor

SasinduDilshara commented Sep 7, 2022

public function main() {
    var res = from string i in "xyz"
    select 1;
}

But isn't it better if we return int[] type from the above query.
It will improve the user experience.

@pcnfernando
Copy link
Member Author

pcnfernando commented Sep 8, 2022

If the user actually needs to create an int[], instead of inferring the type; the user can write the code with a contextually expected type.

public function main() {
    int[] res = from string i in "XYZ" //this works
    select 1;
}

@github-actions
Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@SasinduDilshara
Copy link
Contributor

This issue reopened due to #40497

@pcnfernando
Copy link
Member Author

As per https://ballerina.io/spec/lang/master/#section_6.35.10,
A query-select-expr that constructs a mapping or stream must specify a query-construct-type of map or stream respectively.

@github-actions
Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority/Blocker Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug Type/SpecDeviation
Projects
Archived in project
2 participants