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/31 00:27:00 UTC

[jira] [Resolved] (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 resolved GROOVY-10294.
----------------------------------
    Fix Version/s: 4.0.0-beta-2
       Resolution: Fixed

https://github.com/apache/groovy/commit/c59a02ad15b9b9fd7548860d51fc7f7e643bb12f

> 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
>             Fix For: 4.0.0-beta-2
>
>
> 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)