You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Christopher Smith (Jira)" <ji...@apache.org> on 2020/10/30 19:34:00 UTC
[jira] [Updated] (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 ]
Christopher Smith updated GROOVY-9803:
--------------------------------------
Description:
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.
was:
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}
> 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
> Priority: Major
>
> 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.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)