Thodoris Sotiropoulos created GROOVY-11431:
----------------------------------------------
Summary: missing type error when using a Closure within a ternary
operator
Key: GROOVY-11431
URL: https://issues.apache.org/jira/browse/GROOVY-11431
Project: Groovy
Issue Type: Bug
Components: Static Type Checker
Reporter: Thodoris Sotiropoulos
Probably related to GROOVY-10961.
I have the following program
{code:java}
class Test {
public static void main(String[] args) {
Closure<String> y = () -> "bar";
long x = ((true) ? y : () -> 100).call();
}
}{code}
h3. Actual behavior
The code compiles but I receive the following error at runtime:
{code:java}
Exception in thread "main"
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast
object 'bar' with class 'java.lang.String' to class 'long'
at
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:177)
at
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.longUnbox(DefaultTypeTransformation.java:94)
at Test.main(test.groovy:4) {code}
h3. Expected behavior
The code should have been rejected.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)