Details

    • Type: Sub-task
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1-rc-3
    • Fix Version/s: 2.6.0-alpha-1
    • Component/s: parser-antlr
    • Labels:
      None

      Description

      Declaring and populating an array in line such as:

      Object[] objArr = new Object[]

      { "a", "b", "d" }

      ;

      causes the following exception:

      Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, ModelNumberParser.groovy: 7: unexpected token: , @ line 7, column 45

      It would be better, especially for Java people just learning Groovy, to say something like "Java initialization syntax not supported, use [x, y, z] as DesiredClass[]."

      EDIT: probably filed against a JSR version.

        Issue Links

          Activity

          Hide
          blackdrag Jochen Theodorou added a comment -

          I agree, however it is not so easy to do that, since the compiler thinks it is a closure and the "," doesn't make sense to it.

          Show
          blackdrag Jochen Theodorou added a comment - I agree, however it is not so easy to do that, since the compiler thinks it is a closure and the "," doesn't make sense to it.
          Hide
          mcspanky Martin C. Martin added a comment -

          What about adding a production into the parser? That is, add a "commas inside { }s" construct, whose action is to report an error. Make it triggerable only if no other rule matches. Such error productions are a standard technique, from what I've gathered.

          By the way, why is this ambiguous? Can you declare a return type for a closure? If not, what could the interpretation of:

          new Foo[]

          { bar }

          be if { bar }

          is interpreted as a closure?

          I've finally started reading GinA, I should have a much more complete knowledge of Groovy soon.

          Show
          mcspanky Martin C. Martin added a comment - What about adding a production into the parser? That is, add a "commas inside { }s" construct, whose action is to report an error. Make it triggerable only if no other rule matches. Such error productions are a standard technique, from what I've gathered. By the way, why is this ambiguous? Can you declare a return type for a closure? If not, what could the interpretation of: new Foo[] { bar } be if { bar } is interpreted as a closure? I've finally started reading GinA, I should have a much more complete knowledge of Groovy soon.
          Hide
          aalmiray Andres Almiray added a comment -

          Jochen, I think this may be solved at the same time as the other fixes to the AST code you have been doing lately (definitely just a better error message), pushing this to 1.2 though as it is minor.

          Show
          aalmiray Andres Almiray added a comment - Jochen, I think this may be solved at the same time as the other fixes to the AST code you have been doing lately (definitely just a better error message), pushing this to 1.2 though as it is minor.
          Hide
          paulk Paul King added a comment -

          possibly related

          Show
          paulk Paul King added a comment - possibly related
          Hide
          paulk Paul King added a comment - - edited

          Fixed in Parrot - to be clear, the array syntax is supported, so no need for a better error message.

          Show
          paulk Paul King added a comment - - edited Fixed in Parrot - to be clear, the array syntax is supported, so no need for a better error message.

            People

            • Assignee:
              daniel_sun Daniel Sun
              Reporter:
              mcspanky Martin C. Martin
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development