Index: src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java =================================================================== --- src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java (revision 15129) +++ src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java Tue Jan 20 23:20:59 CET 2009 @@ -1176,7 +1176,8 @@ AST node = labelNode.getFirstChild(); String label = identifier(node); Statement statement = statement(node.getNextSibling()); + if (statement.getStatementLabel() == null) // if statement has multiple labels, retain the last one - statement.setStatementLabel(label); + statement.setStatementLabel(label); return statement; } Index: src/test/groovy/BreakContinueLabelTest.groovy =================================================================== --- src/test/groovy/BreakContinueLabelTest.groovy (revision 15129) +++ src/test/groovy/BreakContinueLabelTest.groovy Tue Jan 20 23:48:26 CET 2009 @@ -1,5 +1,7 @@ package groovy +import org.codehaus.groovy.control.MultipleCompilationErrorsException + /** * todo: add BreakContinueLabelWithClosureTest (when break is used to return from a Closure) @@ -103,4 +105,46 @@ } assertEquals '1323',log } + + void testBreakToLastLabelSucceeds() { + one: + two: + three: + for (i in 1..2) { + break three + fail() -} \ No newline at end of file + } + } + + void testBreakToOtherThanLastLabelCausesSyntaxError() { + try { + new GroovyShell().parse("one: two: three: while (true)\nbreak one") + fail() + } catch (MultipleCompilationErrorsException e) { + def syntaxError = e.errorCollector.getSyntaxError(0) + assert syntaxError + assert syntaxError.line == 2 + } + } + + void testContinueToLastLabelSucceeds() { + one: + two: + three: + for (i in 1..2) { + continue three + fail() + } + } + + void testContinueToOtherThanLastLabelCausesSyntaxError() { + try { + new GroovyShell().parse("one: two: three: while (true)\ncontinue two") + fail() + } catch (MultipleCompilationErrorsException e) { + def syntaxError = e.errorCollector.getSyntaxError(0) + assert syntaxError + assert syntaxError.line == 2 + } + } +} \ No newline at end of file