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]: The typeOf API returns a compilation error type for some expressions when attached to return statement #42009

Closed
nipunayf opened this issue Jan 19, 2024 · 1 comment · Fixed by #42074
Assignees
Labels
Area/SemanticAPI Semantic API Related Issues #Compiler 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

@nipunayf
Copy link
Contributor

Description

When certain expressions, such as query expressions and conditional expressions, are attached to the return statement, the typeOf API returns the compilation error type instead of evaluating the type. However, the expected result is accurately generated for literals and other expressions, such as logical expressions.

function fnTernary(boolean flag) returns boolean {
    return flag ? "True" : false; // Compilation error type
}

function fnQuery() {
    int [] arr = [1,2,3];
    return from var item in arr select item + 1; // // Compilation error type
}

function fnNil(string? val) {
    return val ?: "Hello"; // // Compilation error type
}

function fnCondition(boolean flag) { 
    if (flag) {
        return "True"; // String type
    } 
    return false; // Boolean type
}

function fnBoolean(boolean flag1, boolean flag2) {
    return flag1 || flag2; // Boolean type
}

Steps to Reproduce

Provide the line position between the <START> and <END to the typeOf API of the semantic model

function fnTernary(boolean flag) returns boolean {
    return <START>flag ? "True" : false<END>;
}

Affected Version(s)

Ballerina 2201.8.4 (Swan Lake Update 8)

OS, DB, other environment details and versions

OS: macOS 14.2.1 23C71
JDK: openjdk 17.0.8 2023-07-18

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@nipunayf nipunayf added Type/Bug Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Area/SemanticAPI Semantic API Related Issues #Compiler labels Jan 19, 2024
@nipunayf nipunayf self-assigned this Jan 19, 2024
@nipunayf nipunayf moved this to In Progress in Ballerina Team Main Board Jan 19, 2024
@nipunayf nipunayf moved this from In Progress to On Hold in Ballerina Team Main Board Jan 19, 2024
@nipunayf nipunayf moved this from On Hold to In Progress in Ballerina Team Main Board Jan 19, 2024
@nipunayf nipunayf moved this from In Progress to PR Sent in Ballerina Team Main Board Jan 31, 2024
@github-project-automation github-project-automation bot moved this from PR Sent to Done in Ballerina Team Main Board Feb 5, 2024
Copy link

github-actions bot commented Feb 5, 2024

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.

@nipunayf nipunayf added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Feb 5, 2024
@nipunayf nipunayf added this to the 2201.9.0 milestone Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/SemanticAPI Semantic API Related Issues #Compiler 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
Archived in project
1 participant