Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8220

GroovyCastException with CompileStatic

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.0-beta-1, 2.4.12
    • Fix Version/s: 2.4.13
    • Component/s: None
    • Labels:
      None

      Description

      @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)
      

      Without CompileStatic it works as expected.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jwagenleitner John Wagenleitner
                Reporter:
                pablo72 paolo di tommaso
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: