Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.7
-
None
-
None
Description
The following example:
class Foo { Object propertyMissing(String name) { return "stuff" } void build(Closure callable) { this.with(callable) } } @groovy.transform.CompileStatic class Bar { protected List bar = [] boolean doStuff() { Foo foo = new Foo() foo.build { return bar.isEmpty() } } } new Bar().doStuff()
Produces
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List at Bar$_doStuff_closure1.doCall(ConsoleScript3:19) at Bar$_doStuff_closure1.call(ConsoleScript3) at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:242) at Bar.doStuff(ConsoleScript3:18) at Ba
The equivalent code without CompileStatic prints:
Result: false
The behaviour of both should be he same IMO
Attachments
Issue Links
- is related to
-
GROOVY-9063 Groovy 2.5.6 @CompileStatic generates invalid bytecode (leading to runtime ClassCastException) when accessing protected instance member from 2 level of nested closures
- Closed
- links to