You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Pascal Schumacher (JIRA)" <ji...@apache.org> on 2015/07/13 21:05:04 UTC

[jira] [Updated] (GROOVY-5502) If/else brach does not always infer the variable type

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

Pascal Schumacher updated GROOVY-5502:
--------------------------------------
    Affects Version/s: 2.4.3

> If/else brach does not always infer the variable type
> -----------------------------------------------------
>
>                 Key: GROOVY-5502
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5502
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Static Type Checker
>    Affects Versions: 2.3.0, 2.4.3
>            Reporter: Ariel Morelli Andres
>            Assignee: Cédric Champeau
>            Priority: Minor
>
> Suppose we have the following code:
> {code}
> class A {
>   void mA() {  
>   }
> }
> class B extends A {
> }
> class C extends A {
> }
> @groovy.transform.CompileStatic
> class Test {
>    void m() {
>       def var = new Object()   //If instead I put just "def var" it works as spected
>       if (true) {
>         var = new B()
>       }
>       else {
>         var = new C()
>       }
>       var.mA()                  //fails here
>    }
> }
> {code}
> In this case, after the if/else structure we can infer that var is instanceOf A.
> But, the initialization seems to confuse the type inference.
> [Static type checking] - Cannot find matching method java.lang.Object#mA()
>  at line: 23, column: 7
> If instead of {code}def var = new Object(){code} we put just {code}def var{code}, then the inference works fine.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)