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 23:29:00 UTC

[jira] [Assigned] (GROOVY-10294) Variable's inferred type is upcasted to an Object

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

Eric Milles reassigned GROOVY-10294:
------------------------------------

    Assignee: Eric Milles

> Variable's inferred type is upcasted to an Object
> -------------------------------------------------
>
>                 Key: GROOVY-10294
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10294
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Major
>
> I am not sure if this is a bug or a feature (or a general limitation of flow typing employed by Groovy).
> I have the following program
> {code:java}
> class A {
>   A foo() {
>     def x = new A()
>     if (false) {
>       x = null
>     }
>     x
>   }
> }
> {code}
> h3. Actual behavior
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> test.groovy: 7: [Static type checking] - Cannot return value of type java.lang.Object on method returning type A
>  @ line 7, column 5.
>        x
>        ^
> 1 error
> {code}
> h3. Expected behaviour
> Compile successfully
> Tested against master



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