Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.5.13
-
None
-
None
Description
This started failing with Groovy 2.5.13:
class Node { String name, text } class Root implements Iterable<Node> { @Override Iterator<Node> iterator() { return [ new Node(name: 'term', text: 'foo'), new Node(name: 'dash', text: '-' ), new Node(name: 'term', text: 'bar') ].iterator() } } @groovy.transform.CompileStatic void test() { Root root = new Root() root[0].with { assert name == 'term' assert text == 'foo' } root[1].with { assert name == 'dash' assert text == '-' // GroovyCastException: Cannot cast object 'script@b91d8c4' with class 'script' to class 'bugs.Node' } } test()
Adding a cast to String in front of "-" fixes and @CompileDynamic also fixes. I'm guessing @TypeChecked would not have the issue. I noticed some changes in BinaryExpressionTransformer#tryOptimizeCharComparison that may be relevant.