You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2020/07/23 18:25:00 UTC

[jira] [Created] (GROOVY-9652) ClassCastException for comparison to single-character string literal in closure

Eric Milles created GROOVY-9652:
-----------------------------------

             Summary: ClassCastException for comparison to single-character string literal in closure
                 Key: GROOVY-9652
                 URL: https://issues.apache.org/jira/browse/GROOVY-9652
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.5.13
            Reporter: Eric Milles


This started failing with Groovy 2.5.13:
{code:groovy}
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()
{code}

I noticed some changes in {{BinaryExpressionTransformer#tryOptimizeCharComparison}} that may be relevant.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)