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

Eric Milles updated GROOVY-10625:
---------------------------------
    Priority: Minor  (was: Major)

> Issue in subtyping leads to unsound results
> -------------------------------------------
>
>                 Key: GROOVY-10625
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10625
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Minor
>
> I have the following program
> {code}
> class A<T> {
>   T x;
>   A(T x) {this.x = x;}
>   A() {}
> }
> class B<T extends Object> extends A<T> {
>   B(T x) {
>     super(x);
>   }
>   B() {}
>   T m() {
>     A<T> x = new B<Object>("fd"); // Misses type error: B<Object> is not a 
> subtype of A<T>
>     return x.x;
>   }
> }
> class Test {
>   public static void main(String[] args) {
>     Integer x = new B<Integer>().m();
>   }
> }
> {code}
> h3. Actual behavior
> The above program contains a type error, but the compilers misses it. As a 
> result, a ClassCastException happens at runtime:
> {code}
> Exception in thread "main" 
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 
> object 'fd' with class 'java.lang.String' to class 'java.lang.Integer'
>         at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:180)
>         at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:295)
>         at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:252)
>         at 
> org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318)
>         at Test.main(test.groovy:25)
> {code}
> h3. Expected behaviour
> The compiler should not have type checked the assignment at line 17 and have 
> produced an error message of the form: B<Object> cannot be converted into 
> A<T>.
> Tested against master (commit: ee12bb52381e8f0583c61fc25d43de1f55b80a87)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to