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/12/07 22:10:03 UTC
[jira] [Closed] (GROOVY-9803) Static type checker forgets nested
generic types
[ https://issues.apache.org/jira/browse/GROOVY-9803?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-9803.
-----------------------------
> 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
>
> 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)