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

CompileStatic - Calling vargarg parameter GString is converted to array of strings

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.0.5
    • 2.0.6
    • None
    • Windows 7, JDK 1.7.0_09 64 bits, Groovy 2.0.5 (windows installer)

    Description

      OOPS... It happens again, almost the same bug as http://jira.codehaus.org/browse/GROOVY-5703
      But now we call with GString instead of String

      Assume we have this method:

      static void printMsgs(String ... msgs) {
          for(String s : msgs) { println s;}
      }
      

      Calling it from @CompileStatic:

      @CompileStatic
          static void testCS() {
              String n1="hello"
              //Print:
              // H
              // e
              // l
              // l
              // o
              printMsgs("${n1}");
          }
      

      The string 'hello' is converted to array of strings.

      Calling it from non CompileStatic works fines.
      Also if the passed parameter is String and not GString then it also works fine.

      The complete test case:

      import groovy.transform.CompileStatic
      
      public class CompileStaticVarArg {
      
          static void main(String[] args) {
      
              println GroovySystem.version
              println '-' * 20
      
              test();
      
              println '-' * 20
      
              testCS()
      
          }
      
      
          static void test() {
              String n1="hello"
              // Print 'hello'
              printMsgs("${n1}");
          }
      
          @CompileStatic
          static void testCS() {
              String n1="hello"
              //Print:
              // H
              // e
              // l
              // l
              // o
              printMsgs("${n1}");
          }
      
          //@CompileStatic
          static void printMsgs(String... msgs) {
      
              for (String s : msgs) {
                  println s;
              }
      
          }
      
      }
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            boaznahum Boaz Nahum
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: