[
https://issues.apache.org/jira/browse/GROOVY-12490?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18131623#comment-18131623
]
ASF GitHub Bot commented on GROOVY-12490:
-----------------------------------------
testlens-app[bot] commented on PR #3024:
URL: https://github.com/apache/groovy/pull/3024#issuecomment-6390633061
## ✅ All tests passed ✅
🏷️ Commit: a0819ff9855128940e7dbf057aef716ae3d042f3
▶️ Tests: 123268 executed
⚪️ Checks: 32/32 completed
---
_Learn more about TestLens at
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
> Enum constants with literal arguments still select their constructor
> reflectively through $INIT
> -----------------------------------------------------------------------------------------------
>
> Key: GROOVY-12490
> URL: https://issues.apache.org/jira/browse/GROOVY-12490
> Project: Groovy
> Issue Type: Improvement
> Components: Compiler
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> GROOVY-12240 made enum constants without arguments call the {{(String,int)}}
> constructor directly. Every constant with arguments still goes through the
> synthetic {{$INIT(Object[])}} helper, whose body is a spread {{this(*para)}}:
> {{MetaClassImpl}} selects the constructor by reflecting over the declared
> constructors. {{@CompileStatic}} does not change that, since {{$INIT}}'s own
> body stays dynamic.
> As a result, an ordinary enum fails to initialize in a GraalVM native image
> built without reflection metadata for it:
> {code:groovy}
> enum AccessModifier {
> PRIVATE('private'), PROTECTED('protected'), PUBLIC('public')
> final String keyword
> AccessModifier(String keyword) { this.keyword = keyword }
> }
> {code}
> {noformat}
> groovy.lang.GroovyRuntimeException: Could not find matching constructor for:
> AccessModifier(String, Integer, String)
> {noformat}
> Proposed fix: call the constructor directly when the compiler can prove what
> the runtime would do: every argument is a literal, exactly one non-synthetic
> constructor has the arity and none could take the arguments as varargs, and
> each literal reaches its parameter unchanged ({{Boolean}} parameters
> excluded). Everything else keeps {{$INIT}}, and the decision stays per enum,
> as in GROOVY-12240.
> PR: https://github.com/apache/groovy/pull/3024
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)