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 2021/03/02 15:19:00 UTC

[jira] [Resolved] (GROOVY-9882) STC: field or property with parameterized SAM-type and closure initializer

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

Eric Milles resolved GROOVY-9882.
---------------------------------
    Fix Version/s: 4.0.0-alpha-3
       Resolution: Fixed

> STC: field or property with parameterized SAM-type and closure initializer
> --------------------------------------------------------------------------
>
>                 Key: GROOVY-9882
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9882
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.5.14, 3.0.7, 4.0.0-alpha-2
>            Reporter: Christopher Smith
>            Assignee: Eric Milles
>            Priority: Minor
>             Fix For: 4.0.0-alpha-3
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> In static mode, the compiler correctly coerces closures that match non-generic SAMs to their concrete type, but this breaks in the context of generics.
> {code:groovy}
> Runnable doIt = { '123' } // works fine
> Supplier<String> supplier = { '123' } // error
> {code}
> The error is
> {code}
> Cannot assign value of type groovy.lang.Closure <java.lang.String> to variable of type java.util.function.Supplier <String>
> {code}
> Not sure if it's relevant that the generic in the second case is reported as bare {{<String>}}. Replacing the type parameter with a literal {{<java.lang.String>}} causes the error message to match but does not fix the error. Using {{<Function<String, String>}} produces matching behavior, so it's not just a "skip java.lang", and in the latter case the reported bound is the raw type {{Function}}.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)