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

Set determine type for query and conditional expressions when the expected types are incompatible #42074

Merged
merged 3 commits into from
Feb 5, 2024

Conversation

nipunayf
Copy link
Contributor

@nipunayf nipunayf commented Jan 31, 2024

Purpose

The current implementation of the type checker does not determine the type for query and conditional expressions when the expected type is incompatible. Thus, the typeOf API in the semantic model returns an compilation error type for the respective expressions.

Fixes #42009
Fixes #41864

Approach

Silent type checking is used where applicable to determine the actual type for the respective expressions. Additionally, the FixReturnType code action is modified to consider one more ancestor to support conditional expressions.

Samples

image

Remarks

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

@nipunayf nipunayf added the Team/LanguageServer Language Server Implementation related issues. #Compiler label Jan 31, 2024
Copy link

codecov bot commented Jan 31, 2024

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (fc425a7) 76.68% compared to head (42aff87) 76.69%.
Report is 4 commits behind head on master.

Files Patch % Lines
.../providers/changetype/FixReturnTypeCodeAction.java 40.00% 5 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master   #42074   +/-   ##
=========================================
  Coverage     76.68%   76.69%           
- Complexity    53030    53036    +6     
=========================================
  Files          2883     2883           
  Lines        199951   199967   +16     
  Branches      26034    26035    +1     
=========================================
+ Hits         153340   153357   +17     
  Misses        38146    38146           
+ Partials       8465     8464    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

KavinduZoysa
KavinduZoysa previously approved these changes Jan 31, 2024
Comment on lines +18 to +20
function testNestedElvisExpr1(string? nullableStr) {
return nullableStr ?: false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a arrow function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are test resources for the CAs. We are using this approach because it is more convenient to reproduce the line positions for the CA test cases.

Comment on lines 8 to 15
type Student record {
int id;
string fname;
string lname;
int age;
float gpa;
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type Student record {
int id;
string fname;
string lname;
int age;
float gpa;
};
type Student record {|
int id;
string fname;
string lname;
int age;
float gpa;
|};

Comment on lines 35 to 39
function testQueryExprWithOnConflict() {
return table key(id) from var st in getStudents().toStream()
select <Person>{id: st.id, name: st.fname, age: st.age}
on conflict error("Conflicted Key", cKey = st.id);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions can be arrow functions

@KavinduZoysa KavinduZoysa merged commit 6943c66 into ballerina-platform:master Feb 5, 2024
17 of 18 checks passed
@nipunayf nipunayf added this to the 2201.9.0 milestone Mar 21, 2024
@nipunayf nipunayf added Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Area/TypeChecker Type Checker related issues #Compiler Area/CodeAction Language Server Code Actions labels Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/CodeAction Language Server Code Actions Area/TypeChecker Type Checker related issues #Compiler Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Team/LanguageServer Language Server Implementation related issues. #Compiler
Projects
None yet
3 participants