[ 
https://issues.apache.org/jira/browse/GROOVY-12588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18140516#comment-18140516
 ] 

ASF GitHub Bot commented on GROOVY-12588:
-----------------------------------------

codeconsole commented on PR #3113:
URL: https://github.com/apache/groovy/pull/3113#issuecomment-6717049253

   @daniellansun Merged current master (492ae79db4) for a fresh run of the 
Windows cell.
   
   On the helper: this PR and #3133 each add a private 
`isClosureCoercibleToSAM` to `StaticTypeCheckingVisitor`, so whichever lands 
second would not compile next to the other. The land order is #3113 → #3126 → 
#3133:
   
   - Once this PR is in, I'll merge master into #3126 and replace this PR's 
copy with the `StaticTypeCheckingSupport` one. The Closure and SAM guards that 
the assignment and return callers rely on move into that helper.
   - Once #3126 is in, #3133 does the same.
   
   I checked that end state on a local merge of the three with one shared 
helper: `CoercionSTCTest`, `ClosuresSTCTest`, `LambdaTest`, 
`CoercionStaticCompileTests` and `ReturnConversionConsistencyTest` pass. The 
Support rule is more lenient (it accepts a raw Closure, `Closure<Object>`, an 
unresolved `R`, and GString for String), and every negative case of this PR and 
#3133 is still an error.
   




> 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)

Reply via email to