[ https://issues.apache.org/jira/browse/GROOVY-8891?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16691193#comment-16691193 ]
Paul King commented on GROOVY-8891: ----------------------------------- This is really a grammar issue which we aren't likely to fix. Add a semicolon or numerous other constructs like a method definition after the 0 and it will work. > Trait Instance Init Block causes Runtime exception for Trait fields with > default values > --------------------------------------------------------------------------------------- > > Key: GROOVY-8891 > URL: https://issues.apache.org/jira/browse/GROOVY-8891 > Project: Groovy > Issue Type: Bug > Components: Compiler, groovy-runtime > Affects Versions: 2.5.5 > Reporter: Anton Pryamostanov > Priority: Major > > With ref. to GROOVY-8880, when instance or static field has default value in > Trait, when same Trait has Instance Init Block, Runtime exception happens. > Example code: > {code} > trait Trait { > Integer fieldWithDefaultValue = 0 > { > System.out.println("Only instance init block gives this problem") > } > } > class ClassWithTrait implements Trait { > } > new ClassWithTrait().fieldWithDefaultValue > {code} > Runtime exception: > {code} > groovy.lang.MissingMethodException: No signature of method: > java.lang.Integer.call() is applicable for argument types: > (Trait$Trait$Helper$__init__closure1) values: > [Trait$Trait$Helper$__init__closure1@5833d058] > Possible solutions: wait(), abs(), any(), wait(long), > each(groovy.lang.Closure), any(groovy.lang.Closure) > at Trait$Trait$Helper.$init$(ConsoleScript80:3) > at ClassWithTrait.<init>(ConsoleScript80) > at ConsoleScript80.run(ConsoleScript80:9) > {code} > Note: It does not matter if field is static of instance. > Note 2: Static Init Block in Trait does not cause same issue and works Ok. -- This message was sent by Atlassian JIRA (v7.6.3#76005)