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 2020/06/02 18:38:01 UTC
[jira] [Commented] (GROOVY-9344) CCE in closure shared variable
assignment
[ https://issues.apache.org/jira/browse/GROOVY-9344?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17124198#comment-17124198 ]
Eric Milles commented on GROOVY-9344:
-------------------------------------
Variable metadata is saved before visiting a closure expression and restored afterwards. This resets the inferred type of "var" to A and so when classgen runs, "var = new B()" has a cast inserted for the inferred type A.
> CCE in closure shared variable assignment
> -----------------------------------------
>
> Key: GROOVY-9344
> URL: https://issues.apache.org/jira/browse/GROOVY-9344
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation, Static Type Checker
> Affects Versions: 2.5.8
> Reporter: Daniil Ovchinnikov
> Assignee: Eric Milles
> Priority: Major
>
> {code}
> class A {}
> class B {}
> @groovy.transform.CompileStatic
> def cs() {
> def var
> var = new A()
> def c = {
> var = new B() // Cannot cast object 'B@4e234c52' with class 'B' to class 'A'
> }
> c()
> var.toString()
> }
> assert cs() != null
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)