Bug 21912

Summary: Compiler probleme: continue statement with label identifier
Product: [Eclipse Project] JDT Reporter: Luc Bourlier <eclipse>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 2.0   
Target Milestone: 2.1 M1   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Luc Bourlier CLA 2002-07-25 12:36:14 EDT
In the case of multiple label before a loop statement (for, do, while), if there
is a continue statement with a label identifier which not represent the label
just before the loop statement, the compiler should generate a compilation error.

Example:
public class Test {
  public static void main(String[] args) {
    a : b : for (int i= 0; i < 10; i++) {
      if (i % 2  == 0)
        continue b;
      if (i % 2  == 1)
        continue a;
    }
  }
}


see the Java Language Spec, §14.15
"A continue statement with label Identifier attempts to transfer control to the
enclosing labeled statement (§14.7) that has the same Identifier as its label;
that statement, which is called the continue target, then immediately ends the
current iteration and begins a new one. The continue target must be a while, do,
or for statement or a compile-time error occurs. (...)"

javac generate the correct error:
> javac Test.java
Test.java:7: not a loop label: a
        continue a;
        ^
1 error
Comment 1 Philipe Mulet CLA 2002-07-26 06:22:53 EDT
Good find.
Comment 2 Philipe Mulet CLA 2002-07-26 06:26:37 EDT
Note that javac 1.3.1 did allow such code.
Comment 3 Philipe Mulet CLA 2002-07-26 12:45:15 EDT
Fixed (LabelStatement#concreteStatement()).
Comment 4 David Audel CLA 2002-09-19 07:30:27 EDT
Verified.