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/04/07 16:44:00 UTC

[jira] [Updated] (GROOVY-10235) STC: Generic type of Set not correctly resolved when calling ConcurrentHashMap.newKeySet()

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

Eric Milles updated GROOVY-10235:
---------------------------------
    Fix Version/s: 3.0.11

> STC: Generic type of Set not correctly resolved when calling ConcurrentHashMap.newKeySet()
> ------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-10235
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10235
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 4.0.0-beta-1
>         Environment: OpenJDK 8
>            Reporter: Lyuben Atanasov
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-2, 3.0.11
>
>
> The following code fails to compile when STC is enabled:
> {code}
> import java.util.concurrent.ConcurrentHashMap;
> class Test {
>     public void test() {
>         Set<Integer> integers = ConcurrentHashMap.newKeySet();
>         integers.add(1);
>         integers.add(2);
>         printSet(integers);
>     }
>     private void printSet(Set<Integer> integers) {
>         println "$integers";
>     }
> }
> {code}
> The error reported by the compiler is:
> {noformat}
> Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Script_a26d7b8defa71ea9b230673f8bc53d80.groovy: 9: [Static type checking] - Cannot call Test#printSet(java.util.Set<java.lang.Integer>) with arguments [java.util.concurrent.ConcurrentHashMap$KeySetView<java.lang.Object, java.lang.Object>]
>  @ line 9, column 9.
>            printSet(integers);
>            ^
> {noformat}
> This issue is new to 4.0.0-beta-1, it has not been observed before that. It looks like the variable definition is treated as if it was {{def integers}} so the generic type of the Set is not correctly resolved.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)