Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.15, 2.5.3
-
None
Description
Consider this class:
package testgroovy import groovy.transform.CompileStatic @CompileStatic class Foobar { static class Foo { String aaa = 'aaa' String bbb = 'bbb' } static class Bar { String ccc = 'ccc' } Foo foo = new Foo() Bar bar = new Bar() void foobar() { foo.with { bar.with { println aaa println bbb println ccc } } } static void main(String[] args) { new Foobar().foobar() } }
It fails at runtime with:
Exception in thread "main" java.lang.ClassCastException: testgroovy.Foobar$Bar cannot be cast to groovy.lang.Closure at testgroovy.Foobar$_foobar_closure1$_closure2.doCall(Foobar.groovy:23) at testgroovy.Foobar$_foobar_closure1$_closure2.call(Foobar.groovy) at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:369) at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:316) at testgroovy.Foobar$_foobar_closure1.doCall(Foobar.groovy:22) at testgroovy.Foobar$_foobar_closure1.call(Foobar.groovy) at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:369) at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:316) at testgroovy.Foobar.foobar(Foobar.groovy:21) at testgroovy.Foobar.main(Foobar.groovy:31)
It works fine if you remove @CompileStatic.
Attachments
Issue Links
- is duplicated by
-
GROOVY-8434 ClassCastException: Class cannot be cast to type-of-with's-delegate
- Closed
- links to