You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Shil Sinha (JIRA)" <ji...@apache.org> on 2017/02/04 16:44:52 UTC
[jira] [Commented] (GROOVY-8051) Reference outer class property
within inner class closure
[ https://issues.apache.org/jira/browse/GROOVY-8051?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15852847#comment-15852847 ]
Shil Sinha commented on GROOVY-8051:
------------------------------------
[~daniilo] have you tried this on 2.4.8? I wasn't able to reproduce the error there.
> Reference outer class property within inner class closure
> ---------------------------------------------------------
>
> Key: GROOVY-8051
> URL: https://issues.apache.org/jira/browse/GROOVY-8051
> Project: Groovy
> Issue Type: Bug
> Components: Compiler, Static compilation, Static Type Checker
> Affects Versions: 2.4.7
> Reporter: Daniil Ovchinnikov
>
> {code}
> @CompileStatic // works without this @CompileStatic
> class Outer {
> def foo = 1
> Inner createInner() { new Inner() }
> class Inner {
> Closure createClosure() {
> return { foo }
> }
> }
> }
> @CompileStatic
> class Main {
> static void main(String[] args) {
> def i = new Outer().createInner()
> def cl = i.createClosure()
> println cl()
> }
> }
> {code}
> Fail in runtime with:
> {noformat}
> Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException:
> Cannot cast object 'Outer$Inner@23e028a9' with class 'Outer$Inner' to class 'Outer'
> at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
> at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
> at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
> at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
> at Outer$Inner$_createClosure_closure1.doCall(innerclassestest.groovy)
> at Outer$Inner$_createClosure_closure1.call(innerclassestest.groovy)
> at Main.main(innerclassestest.groovy:23)
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)