You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/07/23 14:17:05 UTC
[jira] [Closed] (GROOVY-9598) CompileStatic: Runtime error: Access
outer class property from static inner in @DelegatesTo
[ https://issues.apache.org/jira/browse/GROOVY-9598?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-9598.
-----------------------------
> CompileStatic: Runtime error: Access outer class property from static inner in @DelegatesTo
> -------------------------------------------------------------------------------------------
>
> Key: GROOVY-9598
> URL: https://issues.apache.org/jira/browse/GROOVY-9598
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 3.0.4
> Environment: openjdk version "1.8.0_242"
> OpenJDK Runtime Environment (Zulu 8.44.0.11-CA-macosx) (build 1.8.0_242-b20)
> OpenJDK 64-Bit Server VM (Zulu 8.44.0.11-CA-macosx) (build 25.242-b20, mixed mode)
> Reporter: Felix Scheinost
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.0-alpha-1, 3.0.5
>
> Time Spent: 1h
> Remaining Estimate: 0h
>
> When trying to access the property of a outer class from a static inner class the code should fail to compile.
> It doesn't fail to compile when the access happens from inside a @DelegatesTo Closure.
>
> {code:groovy}
> import groovy.transform.CompileStatic
> @CompileStatic
> class Delegate {
> static void delegate(@DelegatesTo(Delegate) Closure c) {
> c.delegate = new Delegate()
> c()
> }
> }
> @CompileStatic
> class Outer {
> String propertyName
> static class Inner {
> void someFunction() {
> // Moving this here results in a compilation error
> // println(propertyName)
> Delegate.delegate {
> // This causes a GroovyCastException at runtime because the generated code tries to access propertyName as if this were a instance of Outer?
> println(propertyName)
> }
> }
> }
> }
> new Outer.Inner().someFunction()
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)