Scott Murphy Heiberg created GROOVY-12600:
---------------------------------------------

             Summary: 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


{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.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to