You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/02/24 22:30:00 UTC

[jira] [Commented] (GROOVY-9952) STC does not correctly type check variable whose type is a type variable

    [ https://issues.apache.org/jira/browse/GROOVY-9952?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17290503#comment-17290503 ] 

Eric Milles commented on GROOVY-9952:
-------------------------------------

Is is the check here where "left" is "T -> Object" and "right" is "Y".  When I tried checking also that right is a generics placeholder, there were a number of other failures, including raw type scenarios like "Map m; m['k'] = ..." where the left type for the assignment check is "V" from Map or putAt.

https://github.com/apache/groovy/blob/1fcbd7ed874ee2a792870644276c7a89a416f379/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L653

> STC does not correctly type check variable whose type is a type variable
> ------------------------------------------------------------------------
>
>                 Key: GROOVY-9952
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9952
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Priority: Major
>
> I have the following program
>  
> {code:java}
> class Y {}
> class X<T> {
>     T x;
>     public X() {
>       this.x = new Y()
>     }
>     T foo() { return this.x }
> }
> class Main {
>   public static void main(String[] args) {
>     bar(new X<Integer>());
>   }
>   public static Integer bar(X<Integer> y) {
>     return y.foo()
>   }
> }
> {code}
> h3. Actual Behaviour
> The program above complies, and at runtime I get the exception
> {code:java}
> Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Y@57175e74' with class 'Y' to class 'java.lang.Integer'
>         at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:175)
>         at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:282)
>         at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:243)
>         at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318)
>         at Main.bar(groovy1.groovy:19)
>         at Main.main(groovy1.groovy:15)
> {code}
> h3. Expected Behaviour
> The program should not compile. The problem is at line 5 where you assign something of type Y to a variable of type T.



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