Scott Murphy Heiberg created GROOVY-12686:
---------------------------------------------
Summary: SC: a private field of the outer class used in an enum
constant body or in an anonymous subclass created in a static method fails with
VerifyError
Key: GROOVY-12686
URL: https://issues.apache.org/jira/browse/GROOVY-12686
Project: Groovy
Issue Type: Bug
Components: Static compilation
Affects Versions: 5.0.8, 4.0.32, 6.0.0
Reporter: Scott Murphy Heiberg
{code:groovy}
@groovy.transform.CompileStatic
enum E {
A { String d() { [f, this.f, { -> f }()].join(',') } }
private String f = 'e'
String d() { f }
}
println E.A.d()
@groovy.transform.CompileStatic
class Outer {
private String f = 'outer'
static String m() { new Outer() { String toString() { [f, this.f, { -> f
}()].join(',') } }.toString() }
}
println Outer.m()
{code}
*Actual:* {{VerifyError: Bad type on operand stack}} ... {{Type 'E$1' (current
frame, stack[3]) is not assignable to 'groovy/lang/Closure'}}, and the same for
{{Outer$1}}. Each form fails on its own, and so does a write such as {{f =
'a'}}.
*Expected:* {{e,e,e}} and {{outer,outer,outer}}: the field of this instance, as
GROOVY-12533 gives for a static nested subclass of the declaring class, which
has no enclosing instance either.
Cause: since GROOVY-12533,
{{StaticCompilationTransformer.hasEnclosingInstanceOf}} decides between
{{this}} and {{DeclaringClass.this}} for such a field. It treats only a class
with the static modifier as having no enclosing instance, so it reads the field
through {{E.this}} or {{Outer.this}}. An enum constant body and an anonymous
class created in a static method have no enclosing instance either.
Dynamic Groovy and {{@TypeChecked}} throw {{MissingPropertyException}} for
these forms, and that is unchanged.
Verified on 5.0.8, 6.0.0 and master. On 4.0.32 the closure form fails with the
same {{VerifyError}}, and the other forms throw {{MissingPropertyException}}.
On master {{this.@f}} in the enum constant body already works.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)