You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/11/11 02:01:05 UTC
[jira] [Closed] (GROOVY-9652) SC: ClassCastException for comparison
to single-character string literal in closure
[ https://issues.apache.org/jira/browse/GROOVY-9652?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-9652.
-----------------------------
> SC: 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
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.0-alpha-1, 2.5.14, 3.0.6
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> 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}
> 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.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)