[
https://issues.apache.org/jira/browse/GROOVY-12626?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Scott Murphy Heiberg updated GROOVY-12626:
------------------------------------------
Description:
{code:groovy}
@groovy.transform.CompileStatic
enum E { A { def n() { z } }; private String z = 'x' }
assert E.A.n() == 'x'
{code}
Actual: {{java.lang.VerifyError: Bad type on operand stack}}. The same happens
for this.z, assignment, compound assignment, a closure, a lambda or an
anonymous class in the constant body. It also happens for an anonymous subclass
created in a static method of the declaring class:
{code:groovy}
@groovy.transform.CompileStatic
class B { private String z = 'x'; static B make() { new B() { String toString()
{ z } } } }
assert B.make().toString() == 'x'
{code}
Expected: the field the class inherits is read and written; both scripts pass.
Cause: the static compiler rewrites the field access through the enclosing E
instance because it treats the constant body (and the anonymous class) as
having an enclosing instance of the declaring class. Neither has one: the
constant body is created by the enum's static initializer, and the anonymous
class by a static method.
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/3152
was:
{code:groovy}
@groovy.transform.CompileStatic
enum E { A { def n() { z } }; private String z = 'x' }
assert E.A.n() == 'x'
{code}
Actual: {{java.lang.VerifyError: Bad type on operand stack}}. The same happens
for this.z, assignment, compound assignment, a closure, a lambda or an
anonymous class in the constant body. It also happens for an anonymous subclass
created in a static method of the declaring class:
{code:groovy}
@groovy.transform.CompileStatic
class B { private String z = 'x'; static B make() { new B() { String toString()
{ z } } } }
assert B.make().toString() == 'x'
{code}
Expected: the field the class inherits is read and written; both scripts pass.
Cause: the static compiler rewrites the field access through the enclosing E
instance because it treats the constant body (and the anonymous class) as
having an enclosing instance of the declaring class. Neither has one: the
constant body is created by the enum's static initializer, and the anonymous
class by a static method.
Seen in 5.0.8 and 6.0.0; 4.0.33 compiles it to a dynamic access that throws
MissingPropertyException.
> SC: a bare private field name in an enum constant body, or in an anonymous
> subclass created in a static method, fails with VerifyError
> --------------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12626
> URL: https://issues.apache.org/jira/browse/GROOVY-12626
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 5.0.8, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> @groovy.transform.CompileStatic
> enum E { A { def n() { z } }; private String z = 'x' }
> assert E.A.n() == 'x'
> {code}
> Actual: {{java.lang.VerifyError: Bad type on operand stack}}. The same
> happens for this.z, assignment, compound assignment, a closure, a lambda or
> an anonymous class in the constant body. It also happens for an anonymous
> subclass created in a static method of the declaring class:
> {code:groovy}
> @groovy.transform.CompileStatic
> class B { private String z = 'x'; static B make() { new B() { String
> toString() { z } } } }
> assert B.make().toString() == 'x'
> {code}
> Expected: the field the class inherits is read and written; both scripts pass.
> Cause: the static compiler rewrites the field access through the enclosing E
> instance because it treats the constant body (and the anonymous class) as
> having an enclosing instance of the declaring class. Neither has one: the
> constant body is created by the enum's static initializer, and the anonymous
> class by a static method.
> 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/3152
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)