groovy
  1. groovy
  2. GROOVY-3298

Support multiple labels on the same statement

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6-rc-1
    • Fix Version/s: 2.4.0-beta-3
    • Component/s: Compiler, parser-antlr
    • Labels:
      None
    • Number of attachments :
      1

      Description

      Unlike Java, Groovy doesn't support multiple labels on the same statement - instead, the AST builder discards all but the first (!) label:

      class MultipleLabels {
      static void main(args) {
      label1:
      label2:
      while (true)

      { break label1 // OK break label2 // Compile error: "break to missing label" }


      }
      }

      For a discussion see: http://www.nabble.com/Multiple-labels-on-the-same-statement-td21543898.html

        Activity

        Hide
        Peter Niederwieser added a comment -

        Here is a trivial patch to retain the last label instead of the first one, which is already an improvement. For 1.6.1 we can maybe do even better and have full support for multiple labels.

        Show
        Peter Niederwieser added a comment - Here is a trivial patch to retain the last label instead of the first one, which is already an improvement. For 1.6.1 we can maybe do even better and have full support for multiple labels.
        Hide
        Guillaume Laforge added a comment -

        Peter, haven't you made that change, I don't recall?

        Show
        Guillaume Laforge added a comment - Peter, haven't you made that change, I don't recall?
        Hide
        Peter Niederwieser added a comment -

        I did apply the trivial patch. What I didn't do is to add true support for multiple labels, because the simple solution I had in mind didn't work.

        Show
        Peter Niederwieser added a comment - I did apply the trivial patch. What I didn't do is to add true support for multiple labels, because the simple solution I had in mind didn't work.
        Hide
        Guillaume Laforge added a comment -

        So what should we do about this issue? Close it? Keep it?

        Show
        Guillaume Laforge added a comment - So what should we do about this issue? Close it? Keep it?
        Hide
        Peter Niederwieser added a comment -

        Should we tweak the parser s.t. multiple labels on the same statement result in a syntax error? That's certainly better than silently dropping labels.

        Show
        Peter Niederwieser added a comment - Should we tweak the parser s.t. multiple labels on the same statement result in a syntax error? That's certainly better than silently dropping labels.
        Hide
        Guillaume Laforge added a comment -

        Btw, what does Java do in this regard?

        Show
        Guillaume Laforge added a comment - Btw, what does Java do in this regard?
        Hide
        Peter Niederwieser added a comment -

        Java does allow multiple labels on the same statement (checked both the spec and Sun's implementation).

        Show
        Peter Niederwieser added a comment - Java does allow multiple labels on the same statement (checked both the spec and Sun's implementation).
        Hide
        Guillaume Laforge added a comment -

        Okay, so we should be consistent here, and follow the Java lead by allowing multiple labels too.
        So let's keep the issue open for the moment.

        Show
        Guillaume Laforge added a comment - Okay, so we should be consistent here, and follow the Java lead by allowing multiple labels too. So let's keep the issue open for the moment.
        Hide
        Peter Niederwieser added a comment -

        In my opinion, supporting multiple labels isn't worth it for Groovy, at least not for 1.x. What seems more important is to prevent the silent dropping of labels (i.e. to be honest about what we currently support). This should be a simple fix that doesn't require any changes to the grammar or AST.

        Show
        Peter Niederwieser added a comment - In my opinion, supporting multiple labels isn't worth it for Groovy, at least not for 1.x. What seems more important is to prevent the silent dropping of labels (i.e. to be honest about what we currently support). This should be a simple fix that doesn't require any changes to the grammar or AST.
        Hide
        Paul King added a comment -
        Show
        Paul King added a comment - Proposed fix here: https://github.com/groovy/groovy-core/pull/394
        Hide
        Paul King added a comment -

        PR applied.

        Show
        Paul King added a comment - PR applied.

          People

          • Assignee:
            Paul King
            Reporter:
            Peter Niederwieser
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: