-
Notifications
You must be signed in to change notification settings - Fork 758
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
Conversation
Codecov ReportAttention:
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. |
function testNestedElvisExpr1(string? nullableStr) { | ||
return nullableStr ?: false; | ||
} |
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 can be a arrow function
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.
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.
type Student record { | ||
int id; | ||
string fname; | ||
string lname; | ||
int age; | ||
float gpa; | ||
}; | ||
|
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.
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; | |
|}; | |
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); | ||
} |
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.
These functions can be arrow functions
6943c66
into
ballerina-platform:master
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
Remarks
fix return type
CA, the current implementation only considers nested expressions up to two levels. Hence, the CA does not provide nested expressions deeper than 2 levels as it is not a priority and impacts the performance of the common use case.fix return type
CA for structural constructor expressions #42076Fix return type
CA does not support function expressions #42103Check List