You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Stefanos Chaliasos (Jira)" <ji...@apache.org> on 2021/06/08 09:17:00 UTC

[jira] [Updated] (GROOVY-10096) STC: accepts incorrect program with flow typing

     [ https://issues.apache.org/jira/browse/GROOVY-10096?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefanos Chaliasos updated GROOVY-10096:
----------------------------------------
    Component/s: Static Type Checker
                 Static compilation

> STC: accepts incorrect program with flow typing
> -----------------------------------------------
>
>                 Key: GROOVY-10096
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10096
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>    Affects Versions: 4.0.0-alpha-2, 3.0.8
>            Reporter: Stefanos Chaliasos
>            Priority: Major
>
> I have the following Groovy program.
> {code:groovy}
> @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() {}
> }
> {code}
> h2. Actual Behavior
> The program does not compile, and I get the following error.
> {code:java}
> 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)
> {code}
> h2. Expected Behavior
> Compile-time error.
> h2. Affected Version
> This programs have been tested with the compiler from the master (commit: e33e2849e247608c5e1826b76098d3a68d16bebf), 4.0.0-alpha-2, and 3.0.8.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)