-
Notifications
You must be signed in to change notification settings - Fork 55
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
Add conformance tests for trap-expr #1085
Add conformance tests for trap-expr #1085
Conversation
function foo() returns int { | ||
return 0; | ||
} | ||
|
||
function errorFunction() { | ||
int _ = trap 2 / foo(); // @error incompatible types: expected 'int', found '(int|error)' | ||
error e = trap 2 / foo(); // @error incompatible types: expected 'error', found 'int' |
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.
Isn't the test overly complicated? We don't need a function call. Even a variable reference would suffice.
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.
Changed
function foo() returns int { | ||
return 0; | ||
} | ||
|
||
function errorFunction() { | ||
int _ = trap 2 / foo(); // @error incompatible types: expected 'int', found '(int|error)' | ||
error e = trap 2 / foo(); // @error incompatible types: expected 'error', found 'int' |
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.
Is the error correct?
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.
Created an issue and moved this test to failing tests
int|error t1 = trap trap 2 / foo(); | ||
io:println(t1); // @output error("{ballerina}DivisionByZero",message=" / by zero") | ||
} | ||
|
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.
Do you have tests for when the expression doesn't panic?
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.
Added few tests at the bottom
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.
Is it the test immediately after this? Can we improve the descriptions to specifically mention that they don't panic?
cf23ec1
to
8d3942d
Compare
@@ -0,0 +1,351 @@ | |||
Test-Case: output | |||
Description: Test evaluation of expression resulting in value v, |
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.
Do we need this? It's not clear what v
is. I would say
Description: Test evaluation of expression resulting in value v, | |
Description: Test the result of the trap expression being `e`, when evaluation of the expression completes abruptly with panic with associated value `e`. |
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.
Please recheck all descriptions. We need to make the concise, but self-explanatory and clear.
} | ||
|
||
Test-Case: output | ||
Description: Test trap expression when the expression is a type-cast-expr. |
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.
Description: Test trap expression when the expression is a type-cast-expr. | |
Description: Test trap expression when the expression is a type cast expression. |
Please update wherever applicable.
int|error t1 = trap trap 2 / foo(); | ||
io:println(t1); // @output error("{ballerina}DivisionByZero",message=" / by zero") | ||
} | ||
|
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.
Is it the test immediately after this? Can we improve the descriptions to specifically mention that they don't panic?
8d3942d
to
fb67a16
Compare
} | ||
|
||
Test-Case: output | ||
Description: Test trap expression when the expression is a numeric-literal and it does not panic. |
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.
When does a numeric literal panic?
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.
Same for string.
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.
Thoughts on this?
Let's also remove the productions from the descriptions everywhere.
numeric-literal -> numeric literal
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.
Fixed in 5303f62
} | ||
|
||
Test-Case: output | ||
Description: Test trap expression when the expression is a byte value and it does not panic. |
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.
Can we add some tests with function calls here instead of literals and variable reference expressions that we know will never panic?
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.
@MaryamZi, do you mean here to add function calls that causes panic or add functions that return literal?
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.
Like a function call, which at compile-time we don't know if it will panic.
function init() {
int|error a = trap fn("1");
io:println(a);
}
function fn(string str) returns int {
return checkpanic int:fromString(str);
}
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.
Changed
530a9c8
to
5303f62
Compare
} | ||
|
||
Test-Case: output | ||
Description: Test trap expression when the expression is a function call which returns subtype of int or panic. |
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.
Description: Test trap expression when the expression is a function call which returns subtype of int or panic. | |
Description: Test trap expression when the expression is a function call which returns a subtype of int or panics. |
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.
Please fix wherever applicable.
} | ||
|
||
Test-Case: output | ||
Description: Test trap expression when the expression is a query expression |
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.
Description: Test trap expression when the expression is a query expression | |
Description: Test trap expression when the expression is a query expression. |
|
||
function init() { | ||
int zero = 0; | ||
int|error e1 = trap (check 2 / zero); |
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.
I think this is a bug. trap
captures a panic. check
should return the error from the function. Can you recheck in the spec and create a spec issue if required or a lang issue?
int[] i = []; | ||
return i[3]; |
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.
Missing member access related labels in Labels
.
|
||
function init() { | ||
Obj obj = new(); | ||
error? t = trap obj.bar(); |
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 doesn't match the description.
Test trap expression when the expression is a new expression.
panic error("msg"); | ||
} | ||
}; | ||
error? e = trap obj.bar(); |
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.
Also doesn't match the description.
Purpose
Fixes ballerina-platform/ballerina-lang#35814