Details
Description
Hi all!
The following code doesn't compile on my machine with Groovy 3.0.11. But it does compile with 3.0.10 and 4.0.2:
@CompileStatic class TestClass2 { def <T extends Number> Set<T> fill(Iterable<T> a_consumable) { Set<T> result = new HashSet<>() a_consumable.forEach { result.add(it) } return result } }
The compilation fails with the following output:
9: [Static type checking] - Cannot call java.util.HashSet <T>#add(T) with arguments [java.lang.Object]
Expected behavior:
AFAICT, this code should compile, as the type of it can be derived.
Additional remarks:
Interestingly, the code compiles if I replace {{ <T extends Number> }} with just {{ <T> }}. An explicit cast also helps. So workaround is easy.
If you need more info, feel free to ask!
Attachments
Attachments
Issue Links
- is related to
-
GROOVY-10049 STC fails when calling a generic method from another generic method
- Closed
-
GROOVY-10436 STC: closure parameter type-checking: declared vs inferred
- Closed