Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.6
-
None
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.
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> } }
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 } }
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.
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?).
Attachments
Issue Links
- is related to
-
GROOVY-7992 Sort methods that accept a comparator should accept Comparator<? super T> (fix type checker ability to cope with super in DGM methods)
- Closed
- relates to
-
GROOVY-11259 STC loses generic information on method references
- Closed