Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.6.4
    • Fix Version/s: 2.6.0-alpha-1
    • Component/s: syntax
    • Labels:
      None

      Description

      Run the attached one line file and you get:

      ================================================================
      C:\Temp>groovyc arrayInitializer.groovy
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,
      arrayInitializer.groovy: 3: No expression for the array constructor call at line
      : 3 column: 29. File: arrayInitializer.groovy @ line 3, column 29.
      String[] junk = new String[]

      {"xxx"}

      ;
      ^

      1 error

      =================================================================

      Of course the line is perfectly correct. Try the attached java file which is an exact
      copy of the groovy file. It compiles fine.

      1. arrayInitializer.groovy
        0.1 kB
        Steve Buroff
      2. ArrayInitializer.java
        0.1 kB
        Steve Buroff

        Issue Links

          Activity

          Hide
          blackdrag Jochen Theodorou added a comment -

          The array initializer syntax is not supported by groovy

          Show
          blackdrag Jochen Theodorou added a comment - The array initializer syntax is not supported by groovy
          Hide
          blackdrag Jochen Theodorou added a comment -

          I changed the issue type to "new feature" since this is no bug, but a RFE

          Show
          blackdrag Jochen Theodorou added a comment - I changed the issue type to "new feature" since this is no bug, but a RFE
          Hide
          paulk Paul King added a comment -

          This doesn't surprise me. The array initialisation syntax has traditionally not been supported in Groovy. We have the explicit list notation and coercion via the 'as' operator. So the obvious workaround is:

          String[] junk = ["xxx"] as String[]
          

          or even this:

          String[] junk = ["xxx"]
          

          Now that we have added back in inner class support though, I wonder if any ambiguity in the grammar remains if we try to support some of these cases.

          Interestingly, while I was expecting an error, this code:

          String[] junk = new String[]["xxx"]
          

          gives this error (which needs some work):

          BUG! exception in phase 'conversion' in source unit 'ConsoleScript5' null
          Caused by: java.lang.NullPointerException
          
          Show
          paulk Paul King added a comment - This doesn't surprise me. The array initialisation syntax has traditionally not been supported in Groovy. We have the explicit list notation and coercion via the 'as' operator. So the obvious workaround is: String [] junk = [ "xxx" ] as String [] or even this: String [] junk = [ "xxx" ] Now that we have added back in inner class support though, I wonder if any ambiguity in the grammar remains if we try to support some of these cases. Interestingly, while I was expecting an error, this code: String [] junk = new String [][ "xxx" ] gives this error (which needs some work): BUG! exception in phase 'conversion' in source unit 'ConsoleScript5' null Caused by: java.lang.NullPointerException
          Hide
          daniel_sun Daniel Sun added a comment -

          Fixed in the parrot branch

          Show
          daniel_sun Daniel Sun added a comment - Fixed in the parrot branch

            People

            • Assignee:
              daniel_sun Daniel Sun
              Reporter:
              hermit69 Steve Buroff
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development