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

Eric Milles reassigned GROOVY-9635:
-----------------------------------

    Assignee: Eric Milles

> Generic types get mixed up
> --------------------------
>
>                 Key: GROOVY-9635
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9635
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.15, 3.0.4
>            Reporter: Felix Scheinost
>            Assignee: Eric Milles
>            Priority: Major
>
> When having a generic function inside a generic class with a constraint the 
> generic types somehow get mixed up.
> In the following example the variable v should have the type V. But the 
> generated bytecode contains a cast to the constraint on the generic type of 
> the class.
>  
> {code:java}
> import groovy.transform.CompileStatic
> import java.util.function.Function
> @CompileStatic
> class Test<R extends Integer> {
>   def <V> V method(Function<Test, V> f) {
>     /**
>      * org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot 
> cast object '' with class 'java.lang.String' to class 'java.lang.Integer'
>      *        at Test.traverseFindResult(ConsoleScript4:7)
>      *        at Test$traverseFindResult.call(Unknown Source)
>      *        at ConsoleScript4.run(ConsoleScript4:12)
>      */
>     def v = f.apply(this) // V v = f.apply(this) doesn't work as well, but 
> directly returning without assignment works
>     return v
>   }
> }
> new Test().method(new Function<Test, String>() {
>   @Override
>   String apply(Test test) {
>     ""
>   }
> })
> {code}
>  



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

Reply via email to