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 14:59:00 UTC

[jira] [Resolved] (GROOVY-9953) Type from flow typing is not propagated in variable assignments

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

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

> Type from flow typing is not propagated in variable assignments
> ---------------------------------------------------------------
>
>                 Key: GROOVY-9953
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9953
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>    Affects Versions: 3.0.7, 4.0.0-alpha-2
>            Reporter: Stefanos Chaliasos
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-alpha-3
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> I have the following Groovy program.
> {code:groovy}
> class A {}
> @groovy.transform.CompileStatic
> class Main {
>   static A bar(Object x) {
>     if (x instanceof A) {
>       def y = x // Inferred Object and not A
>       y
>     } else {
>       new A()
>     }
>   }
> }
> {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: 9: [Static type checking] - Cannot return value of type java.lang.Object on method returning type A
>  @ line 9, column 7.
>          y
>          ^
> 1 error
> {code}
> h2. Expected Behavior
> Compile successfully.
> h2. Affected Version
> I have also tested it with the compiler from Master (commit: 444f6a5e7f10b75d43d94e7bb4fe771ae384c321).



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