Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
2.4.15, 2.5.8, 3.0.0-beta-3
-
None
-
None
Description
Given the following snippet
import java.util.function.* @groovy.transform.CompileStatic class A { static <T> T f(Function<String, T> funcParam) { T result = funcParam.apply("hello") return result } static <TT> TT g(Function<String, TT> funcParam) { TT result = funcParam.apply("hello") return result } } def result1 = A.f({ String s -> s.length() }) def result2 = A.g({ String s -> s.length() }) assert result1.class == result2.class
one would assume the assertion to pass (with both results being of class Integer). Instead f's type parameter T is apparently confused with Function's type parameter of the same name and we get the following result:
Assertion failed: assert result1.class == result2.class | | | | | '5' | | 5 class java.lang.Integer | false class java.lang.String at ConsoleScript0.run(ConsoleScript0:19)
Originally encountered with Groovy 2.4.15 but also verified to be present on latest stable 2.5.8 as well as 3.0.0-beta-3.
Attachments
Issue Links
- duplicates
-
GROOVY-8409 Static compilation with generic function wrapping BiFunction causes GroovyCastException
- Closed