Chris Briem created GROOVY-10648:
------------------------------------

             Summary: Compile error during static compilation (missing type 
derivation?)
                 Key: GROOVY-10648
                 URL: https://issues.apache.org/jira/browse/GROOVY-10648
             Project: Groovy
          Issue Type: Bug
          Components: Compiler
    Affects Versions: 3.0.11
         Environment: Gradle, Windows
            Reporter: Chris Briem


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:
{code:groovy}
@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
    }
}
{code}
The compilation fails with the following output:

{noformat}
9: [Static type checking] - Cannot call java.util.HashSet <T>#add(T) with 
arguments [java.lang.Object]
{noformat}

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!



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to