Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
4.0.0-alpha-2, 3.0.8
-
None
Description
I have the following Groovy program.
@groovy.transform.TypeChecked class Main { public static Bar buz(Foo bux) { (((true || bux instanceof Bar)) ? bux : new Bar()) } public static void main(String[] args) { buz(new Foo()).bar() } } class Foo { public void foo() {} } class Bar extends Foo { public void bar() {} }
Actual Behavior
The program does not compile, and I get the following error.
Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Foo@2e1792e7' with class 'Foo' to class 'Bar' org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Foo@2e1792e7' with class 'Foo' to class 'Bar' at Main.buz(Main.groovy:6) at Main.main(Main.groovy:9) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Expected Behavior
Compile-time error.
Affected Version
This programs have been tested with the compiler from the master (commit: e33e2849e247608c5e1826b76098d3a68d16bebf), 4.0.0-alpha-2, and 3.0.8.
Attachments
Issue Links
- duplicates
-
GROOVY-7971 @CS flow typing incorrectly casting to map at runtime
- In Progress