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/11/16 21:08:00 UTC

[jira] [Assigned] (GROOVY-10271) Wrong inference when using ternary operator with closure and variable

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

Eric Milles reassigned GROOVY-10271:
------------------------------------

    Assignee: Eric Milles

> Wrong inference when using ternary operator with closure and variable
> ---------------------------------------------------------------------
>
>                 Key: GROOVY-10271
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10271
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>    Affects Versions: 4.0.0-alpha-3, 4.0.0-beta-1, 3.0.9
>            Reporter: Stefanos Chaliasos
>            Assignee: Eric Milles
>            Priority: Major
>
> I have the following Groovy program.
> {code:groovy}
> import java.util.function.Supplier;
> @groovy.transform.TypeChecked
> class Main {
>   static final void foo(Supplier<Integer> x) {}
>   public static final void main() {
>       Supplier<Integer> y = { -> 5 }
>       Supplier<Integer> z = (true) ? y : {-> 5}
>   }
> }
> {code}
> h2. Actual Behavior
> The program does not compile, and I get the following error.
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Main.groovy: 11: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type java.util.function.Supplier<java.lang.Integer>
>  @ line 11, column 29.
>          Supplier<Integer> z = (true) ? y : {-> 5}
>                                ^
> 1 error
> {code}
> h2. Expected Behavior
> Compile successfully.
> h2. Comment
> Tested against 4-beta-1, 4-alpha-3, 3.0.9, and master (commit: b26dbbeabe1e3d27d30c936701b1a571e24d5ab2). Maybe similar to GROOVY-10114, but with function types.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)