[
https://issues.apache.org/jira/browse/GROOVY-12600?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18135640#comment-18135640
]
Scott Murphy Heiberg commented on GROOVY-12600:
-----------------------------------------------
Paul's GROOVY-12533 change on master (ef76fcba75) fixes the main shape reported
here: under static compilation, a bare private field name of the outer class
inside a static nested subclass, including closures in it, now compiles to the
subclass's own field instead of failing verification. One level deeper still
fails on master: an anonymous class, a named inner class, or a closure or
lambda inside one, nested in such a subclass, or an anonymous class in an inner
subclass of a static nested class. These classes do not extend the declaring
class, so the name is still written as Outer.this.@name and fails with a
VerifyError. PR #3127 now builds on Paul's mechanism: when no enclosing
instance of the declaring class exists, it uses the innermost enclosing
instance that inherits the field (Sub.this.@name). It leaves the GROOVY-12533
behaviour unchanged where an enclosing instance of the declaring class exists.
> SC: a private field of the outer class referenced by its bare name in a
> static nested subclass throws VerifyError ("not assignable to
> groovy/lang/Closure")
> -----------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12600
> URL: https://issues.apache.org/jira/browse/GROOVY-12600
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 5.0.8, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> class Base {
> private String z = 'x'
> @groovy.transform.CompileStatic
> static class Sub extends Base {
> def m() { z }
> }
> }
> assert new Base.Sub().m() == 'x'
> {code}
> Actual: the class fails verification when loaded:
> {noformat}
> java.lang.VerifyError: Bad type on operand stack
> Location: Base$Sub.m()Ljava/lang/Object; @1: invokevirtual
> Reason: Type 'Base$Sub' (current frame, stack[0]) is not assignable to
> 'groovy/lang/Closure'
> {noformat}
> The same happens for assignment, compound assignment and increment of the
> bare name, inside closures and lambdas, in an anonymous class within the
> subclass, and for a non-static inner subclass of a static nested class.
> Expected: {{m()}} returns 'x', the field the subclass inherits, as {{this.z}}
> and {{super.z}} already do under static compilation.
> Cause: the type checker resolves the name to the inherited field as a
> nestmate private access, but the static compilation transformer always
> rewrites it to {{Base.this.@z}}. The subclass has no enclosing Base instance,
> so the class generator falls back to the closure path and emits
> {{Closure.getThisObject()}} on a non-closure.
> Seen in 5.0.8 and 6.0.0. 4.0.33 compiles it to a dynamic access that throws
> MissingPropertyException.
> PR: https://github.com/apache/groovy/pull/3127
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)