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

Eric Milles reopened GROOVY-9803:
---------------------------------

Fix for GROOVY-8409 required redesign of {{inferReturnTypeGenerics}}.  This 
seems to be the only issue that required a lot of SAM-type (aka functional 
interface) handling code.  I am working to re-fix before 4.0b1.

> Static type checker forgets nested generic types
> ------------------------------------------------
>
>                 Key: GROOVY-9803
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9803
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 3.0.6
>            Reporter: Christopher Smith
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-alpha-2, 3.0.8
>
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> When using a nested generic type (for example, from Vavr {{Try<Option<T>}}), 
> Groovy forgets the value of the nested type parameter, simply tagging 
> {{Object}} instead of {{T}}.
> {code:java}
> import io.vavr.control.Option;
> import io.vavr.control.Try;
> public class GenericInJava {
>     public static void main(String[] args) {
>         Try.success(123)
>                 .map(Option::of)
>                 .map(o -> o.get().intValue()); // happy; correctly identifies 
> o as Option<Integer>
>     }
> }
> {code}
> {code:groovy}
> import groovy.transform.CompileStatic
> import io.vavr.control.Option
> import io.vavr.control.Try
> @CompileStatic
> class GenericInGroovy {
>     static void main(String[] args) {
>         Try.success(123)
>             .map(Option::of)
>             .map(o -> o.get().intValue()) // produces error below
>     }
> }
> {code}
> {code}
> Groovy:[Static type checking] - Cannot find matching method 
> java.lang.Object#intValue(). Please check if the declared type is correct and 
> if the method exists.
> {code}
> Explicitly inserting a type witness {{.<Option<Integer>>map(Option::of)}} 
> succeeds. Oddly enough, using {{.map({ Option.of(it) })}} also works (maybe 
> it's an interaction glitch involving method references specifically?).



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

Reply via email to