You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/06/04 15:08:00 UTC

[jira] [Resolved] (GROOVY-10648) Compile error during static compilation (missing type derivation?)

     [ https://issues.apache.org/jira/browse/GROOVY-10648?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-10648.
----------------------------------
    Fix Version/s: 3.0.12
       Resolution: Fixed

backport:
https://github.com/apache/groovy/commit/55ba573d7eb3a6b152390f18badd24255a341650

original:
https://github.com/apache/groovy/commit/442676556de6d0403be5df67f2206cff99a73b68

> 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
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 3.0.12
>
>         Attachments: screenshot-1.png
>
>
> 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)