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

[jira] [Updated] (GROOVY-9635) Generic types get mixed up

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

Paul King updated GROOVY-9635:
------------------------------
    Fix Version/s: 2.5.14

> 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
>             Fix For: 4.0.0-alpha-1, 2.5.14, 3.0.6
>
>          Time Spent: 1h 40m
>  Remaining Estimate: 0h
>
> 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)