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/03 22:35:00 UTC
[jira] [Assigned] (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 reassigned GROOVY-10648:
------------------------------------
Assignee: Eric Milles
> 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
>
> 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)