[ 
https://issues.apache.org/jira/browse/GROOVY-12575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18134647#comment-18134647
 ] 

ASF GitHub Bot commented on GROOVY-12575:
-----------------------------------------

testlens-app[bot] commented on PR #3108:
URL: https://github.com/apache/groovy/pull/3108#issuecomment-6514405005

   ## ✅ All tests passed ✅
   
   🏷️ Commit: 62b8141103f870dfc3892eff66077c2f8127d25e
   ▶️ Tests:  125006 executed
   ⚪️ Checks: 26/26 completed
   
   ---
   _Learn more about TestLens at 
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   




> A trait's instance initializer blocks run twice under joint compilation
> -----------------------------------------------------------------------
>
>                 Key: GROOVY-12575
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12575
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, Stub generator / Joint compiler
>    Affects Versions: 4.0.33, 5.0.8, 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> When Groovy and Java sources are compiled together, each instance initializer 
> block of a trait runs twice per instance:
> {code:groovy}
> trait T { List<String> log = []; { log << 'block' } }
> class C implements T {}
> {code}
> {code:java}
> public class J { public static void main(String[] a) { System.out.println(new 
> C().getLog()); } }
> {code}
> {{groovyc -j T.groovy J.java}}, then {{java J}}, prints {{[block, block]}}; 
> compiled without {{-j}}, {{new C().log}} is {{[block]}}. Dynamic and 
> {{@CompileStatic}} implementing classes behave alike.
> The stub generator runs a {{Verifier}} over each class. 
> {{Verifier.visitClass}} clears the object initializer statements of a class 
> after copying them into its constructors, so {{JavaStubGenerator}} saves them 
> first and adds them back afterwards. For an interface or a trait, 
> {{visitClass}} returns before that point and keeps them, so adding them back 
> doubles them, and the trait transformation copies every block into the 
> helper's {{$init$}} twice. Field initializers and static initializer blocks 
> of traits are not affected.
> PR: https://github.com/apache/groovy/pull/3108



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

Reply via email to