groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "paolo di tommaso (JIRA)" <j...@apache.org>
Subject [jira] [Created] (GROOVY-8220) GroovyCastException with CompileStatic
Date Tue, 06 Jun 2017 21:27:18 GMT
paolo di tommaso created GROOVY-8220:
----------------------------------------

             Summary: GroovyCastException with CompileStatic
                 Key: GROOVY-8220
                 URL: https://issues.apache.org/jira/browse/GROOVY-8220
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.5.0-beta-1
            Reporter: paolo di tommaso


{code}
@groovy.transform.CompileStatic
class Foo {
    CharSequence makeEnv( env, StringBuilder result = new StringBuilder() ) {
        if( env instanceof File ) {
            env = env.toPath()
        }
        if( env instanceof String && env.contains('=') ) {
            result << 'export ' << env << ';'
        }

        return result.toString()
    }
}

assert new Foo().makeEnv('X=1') == 'export X=1;'

Exception thrown

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'X=1' with
class 'java.lang.String' to class 'java.lang.Iterable'
	at Foo.makeEnv(ConsoleScript5:10)
	at Foo.makeEnv(ConsoleScript5:4)
	at Foo$makeEnv.call(Unknown Source)
	at ConsoleScript5.run(ConsoleScript5:20)
{code}

Without CompileStatic it works as expected. 



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message