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

Christopher Smith updated GROOVY-11276:
---------------------------------------
    Description: 
There's a chance this is a duplicate of a ticket recently fixed, but it's odd 
enough (and the message is unclear enough) that I'm reposting it.

{code}
Map<String, List<String>> idsForAccounts(Collection<String> persons) {
  Map<Object, Object> fromGraph = retrieve()

  // workaround for buggy database implementation follows
  new HashMap<String, List<String>>().tap { result ->
    putAll(fromGraph as Map<String, List<String>>)
    persons.forEach {
      if (!result.containsKey(it)) {
        result.put(it, emptyList())
      }
    }
  }
}
{code}

{code}
[Static type checking] - Cannot find matching method 
java.util.HashMap#put(java.lang.String, java.util.List<#T>). Please check if 
the declared type is correct and if the method exists.
  @ line 73, column 21.
        result.put(it, emptyList())
        ^
{code}

Update: Using a type witness as {{Collections.<String> emptyList()}} works.

  was:
There's a chance this is a duplicate of a ticket recently fixed, but it's odd 
enough (and the message is unclear enough) that I'm reposting it.

{code}
Map<String, List<String>> idsForAccounts(Collection<String> persons) {
  Map<Object, Object> fromGraph = retrieve()

  // workaround for buggy database implementation follows
  new HashMap<String, List<String>>().tap { result ->
    putAll(fromGraph as Map<String, List<String>>)
    persons.forEach {
      if (!result.containsKey(it)) {
        result.put(it, emptyList())
      }
    }
  }
}
{code}

{code}
[Static type checking] - Cannot find matching method 
java.util.HashMap#put(java.lang.String, java.util.List<#T>). Please check if 
the declared type is correct and if the method exists.
  @ line 73, column 21.
        result.put(it, emptyList())
        ^
{code}

       Priority: Minor  (was: Critical)

> Generics error in method resolution
> -----------------------------------
>
>                 Key: GROOVY-11276
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11276
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 4.0.17
>            Reporter: Christopher Smith
>            Priority: Minor
>
> There's a chance this is a duplicate of a ticket recently fixed, but it's odd 
> enough (and the message is unclear enough) that I'm reposting it.
> {code}
> Map<String, List<String>> idsForAccounts(Collection<String> persons) {
>   Map<Object, Object> fromGraph = retrieve()
>   // workaround for buggy database implementation follows
>   new HashMap<String, List<String>>().tap { result ->
>     putAll(fromGraph as Map<String, List<String>>)
>     persons.forEach {
>       if (!result.containsKey(it)) {
>         result.put(it, emptyList())
>       }
>     }
>   }
> }
> {code}
> {code}
> [Static type checking] - Cannot find matching method 
> java.util.HashMap#put(java.lang.String, java.util.List<#T>). Please check if 
> the declared type is correct and if the method exists.
>   @ line 73, column 21.
>         result.put(it, emptyList())
>         ^
> {code}
> Update: Using a type witness as {{Collections.<String> emptyList()}} works.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to