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/10/30 15:16:00 UTC

[jira] [Resolved] (GROOVY-10306) STC rejects program when assigning a closure that returns a class field

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

Eric Milles resolved GROOVY-10306.
----------------------------------
    Fix Version/s: 4.0.0-beta-2
       Resolution: Fixed

https://github.com/apache/groovy/commit/26aa02c56833cc558cee29658028c817fa992e67

> STC rejects program when assigning a closure that returns a class field
> -----------------------------------------------------------------------
>
>                 Key: GROOVY-10306
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10306
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-2
>
>
> I have the following program
> {code:java}
> import java.util.function.Supplier;
> class Main {
>     byte x = 1;
>     void foo() {
>         Supplier<Number> y =  () -> x;
>         
>     }
> }
> {code}
> h3. Actual behaviour
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Main.java: 8: [Static type checking] - Incompatible generic argument types. Cannot assign java.util.function.Supplier<java.lang.Byte> to: java.util.function.Supplier<java.lang.Number>
>  @ line 8, column 31.
>            Supplier<Number> y =  () -> x;
>                                  ^
> 1 error
> {code}
> h3. Expected behaviour
> Compile successfully
> Note that if `x` is a local variabled defined in function `foo`, groovyc compiles the program successfully.
> Tested against master



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