[
https://issues.apache.org/jira/browse/GROOVY-12588?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Scott Murphy Heiberg updated GROOVY-12588:
------------------------------------------
Description:
{code:groovy}
import java.util.function.Supplier
@groovy.transform.TypeChecked // or @CompileStatic
def m() {
Closure<String> c = { 'a' }
Supplier<String> s = c
s.get()
}
assert m() == 'a'
{code}
Actual result:
{noformat}
[Static type checking] - Incompatible generic argument types. Cannot assign
groovy.lang.Closure<java.lang.String> to:
java.util.function.Supplier<java.lang.String>
{noformat}
Expected result: the script compiles and the closure is coerced to the
interface, as it is for a closure literal, for a raw target ({{Supplier s =
c}}) and in dynamic Groovy.
The same error is reported when the value comes from a property, a subscript, a
field assignment or a generic method returning a Closure, and for SAM types
with parameters such as {{Function<Integer,String>}}. The assignment check
accepts Closure to SAM coercion, but the generics check that follows it
compares {{Closure<String>}} with {{Supplier<String>}} as if Closure had to
implement the interface.
Seen in 4.0.33, 5.0.8, 6.0.0 and master.
PR: https://github.com/apache/groovy/pull/3113
was:
{code:groovy}
import java.util.function.Supplier
@groovy.transform.TypeChecked // or @CompileStatic
def m() {
Closure<String> c = { 'a' }
Supplier<String> s = c
s.get()
}
assert m() == 'a'
{code}
Actual result:
{noformat}
[Static type checking] - Incompatible generic argument types. Cannot assign
groovy.lang.Closure<java.lang.String> to:
java.util.function.Supplier<java.lang.String>
{noformat}
Expected result: the script compiles and the closure is coerced to the
interface, as it is for a closure literal, for a raw target ({{Supplier s =
c}}) and in dynamic Groovy.
The same error is reported when the value comes from a property, a subscript, a
field assignment or a generic method returning a Closure, and for SAM types
with parameters such as {{Function<Integer,String>}}. The assignment check
accepts Closure to SAM coercion, but the generics check that follows it
compares {{Closure<String>}} with {{Supplier<String>}} as if Closure had to
implement the interface.
Seen in 4.0.33, 5.0.8, 6.0.0 and master.
> STC rejects a Closure<R> value assigned to a parameterized functional
> interface ("Incompatible generic argument types")
> -----------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12588
> URL: https://issues.apache.org/jira/browse/GROOVY-12588
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.33, 5.0.8, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> import java.util.function.Supplier
> @groovy.transform.TypeChecked // or @CompileStatic
> def m() {
> Closure<String> c = { 'a' }
> Supplier<String> s = c
> s.get()
> }
> assert m() == 'a'
> {code}
> Actual result:
> {noformat}
> [Static type checking] - Incompatible generic argument types. Cannot assign
> groovy.lang.Closure<java.lang.String> to:
> java.util.function.Supplier<java.lang.String>
> {noformat}
> Expected result: the script compiles and the closure is coerced to the
> interface, as it is for a closure literal, for a raw target ({{Supplier s =
> c}}) and in dynamic Groovy.
> The same error is reported when the value comes from a property, a subscript,
> a field assignment or a generic method returning a Closure, and for SAM types
> with parameters such as {{Function<Integer,String>}}. The assignment check
> accepts Closure to SAM coercion, but the generics check that follows it
> compares {{Closure<String>}} with {{Supplier<String>}} as if Closure had to
> implement the interface.
> Seen in 4.0.33, 5.0.8, 6.0.0 and master.
> PR: https://github.com/apache/groovy/pull/3113
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)