[ 
https://issues.apache.org/jira/browse/GROOVY-9516?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17089731#comment-17089731
 ] 

Konstantin Nisht commented on GROOVY-9516:
------------------------------------------

The matter is not about time when closures are evaluated.
 This code successfully passes typechecking and fails in runtime with cast 
exception, which is bad. If "typeof(z)" was C, it would be compile-time error 
instead of runtime one.
 It is indeed hard to say when the closure will be invoked, so in this 
particular case I'd expect the type of {{z}} to be {{A}} (and get a 
compile-time error).

> Static compiler infers wrong type for implicitly shared variables
> -----------------------------------------------------------------
>
>                 Key: GROOVY-9516
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9516
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 3.0.0, 2.5.11
>            Reporter: Konstantin Nisht
>            Priority: Major
>
> Consider the following code
> {code:groovy}
> class A {}
> class B extends A{ def b() {}}
> class C extends A{}
> @CompileStatic
> static foo() {
>   def x = new B()
>   ({ x = new C() })()
>   def z = x
>   z.b()
> }
> {code}
> Here type of {{z}} in the last line of the method is deduced to be {{B}}. 
> Attempt to execute {{z.b()}} leads to cast exception, which is unexpected 
> under static compilation.



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

Reply via email to