[
https://issues.apache.org/jira/browse/GROOVY-12626?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18135720#comment-18135720
]
ASF GitHub Bot commented on GROOVY-12626:
-----------------------------------------
testlens-app[bot] commented on PR #3152:
URL: https://github.com/apache/groovy/pull/3152#issuecomment-6541091670
## ✅ All tests passed ✅
🏷️ Commit: 0422cd9695ac2349eedb4551db50354a470291c2
▶️ Tests: 122713 executed
⚪️ Checks: 26/26 completed
---
_Learn more about TestLens at
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
> 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)