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

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

> STC does not catch type error when assigning a type parameter to a variable 
> of another type
> -------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-10370
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10370
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Minor
>
> This issue may be related to GROOVY-9952.
> I have the following program
> {code:java}
> class A {}
> class Test {
>   public static void main(String[] args) {
>     A x = m(1)
>     System.out.println(x)
>   }
>   static <T> A m(T x) {
>     return x;
>   }
> }
> {code}
> h3. Actual behaviour
> groovyc accepts and compiles this wrongly-typed program, something that 
> results in a runtime exception.
> {code}
> Exception in thread "main" 
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 
> object '1' with class 'java.lang.Integer' to class 'A'
>         at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:420)
>         at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:331)
>         at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:251)
>         at 
> org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318)
>         at Test.m(test.groovy:9)
>         at Test.main(test.groovy:4)
> {code}
> h3. Expected behaviour
> groovyc should have rejected the above program.
> Tested against master.



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

Reply via email to