Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.5.14
-
None
Description
This odd code works fine in 2.5.13, but explodes in 2.5.14.
My workaround for now is to remove @CompileStatic in production.
Minimal example (spock test):
import groovy.transform.CompileStatic import spock.lang.Specification class FooTest extends Specification { def "test"() { when: new Foo() then: noExceptionThrown() } } @CompileStatic class Foo { private Map<String, String> cache = [:] Foo() { [''].each { cache[''] = '' } } }
Minimal example without Spock, while settings stuff in a map in an .each-iteration outside of Constructor:
new Foo().init() @CompileStatic class Foo { private Map<String, String> cache = [:] Foo() { } void init() { [''].each { cache[it] = it } } }
Full Error:
Expected no exception to be thrown, but got 'org.codehaus.groovy.runtime.typehandling.GroovyCastException' at spock.lang.Specification.noExceptionThrown(Specification.java:118) at FooTest.test(FooTest.groovy:10) Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Foo$_closure1@3fa2213' with class 'Foo$_closure1' to class 'Foo' at Foo$_closure1.doCall(FooTest.groovy:19) at Foo.<init>(FooTest.groovy:18) at FooTest.test(FooTest.groovy:7)
Attachments
Issue Links
- Blocked
-
GROOVY-9771 STC: "putAt" shortcut notation to outer class private field from Closure leads to GroovyCastException
- Closed