My favorites | Sign in
Google
                
New issue | Search
for
| Advanced search | Search tips
Issue 2069: Labeled break statements mis-handled
2 people starred this issue and may be notified of changes. Back to list
 
Reported by joncruiz, Feb 08, 2008
Found in GWT Release: 1.5

Detailed description:
The compiler is generating incorrect code when labeled break statements are
used. A specific case is included below. Run TestApplication in hosted mode
and see the output. Compile it and run it in browser mode and see that the
exception gets thrown. It behaves incorrectly in browser mode because the
entire first switch statement is getting stripped (see OutputJSSnippet).
I've also seen a similar case where the first switch is there but the
labeled break is stripped, however I can't isolate that one and it's in
proprietary code. There may be simpler cases of this, but this is the best
Ive been able to isolate it.


Workaround if you have one:
None that I know of, other than re-factoring the code

Links to the relevant GWT Developer Forum posts:
None that I can find
 
TestApplication.java
1.0 KB Download
OutputJSSnippet.rtf
1.2 KB Download
Comment 1 by hsivonen, May 31, 2008
Attaching a minimal full Eclipse project that demonstrates the problem with GWT 1.5 RC1.
default:
  break label;
is completely lost by the compiler.
gwtloopbug.zip
191 KB Download
Comment 2 by hsivonen, May 31, 2008
The problem also occurs with this pattern:
for (;;) {
  switch(cond) {
    case 1:
     ...
     continue;
    // no default
  }
  break;
}
Comment 3 by scottb@google.com, Jul 01, 2008
(No comment was entered for this change.)
Status: Accepted
Owner: sp...@google.com
Cc: sco...@google.com
Comment 4 by spoon+pe...@google.com, Jul 02, 2008
The problem in TestApplication.java as well as LoopBug.java is that the compiler drops breaks that are in the 
default case of a switch.  Normally such a break is useless because the switch is about to end anyway.  In the 
case of a labeled break, though, the break might be for a surrounding loop and thus should not be dropped.

The attached patch makes DeadCodeElimination hang on to breaks in default cases when they are labeled.


labelledBreakInSwitch-r3159.patch
3.6 KB Download
Status: ReviewPending
Comment 5 by scottb@google.com, Jul 07, 2008
LGTM.
Comment 6 by spoon+pe...@google.com, Jul 08, 2008
Committed at revision 3168.
Status: FixedNotReleased
Comment 7 by scottb@google.com, Jul 08, 2008
(No comment was entered for this change.)
Labels: Category-Compiler Milestone-1_5_RC2 ReviewBy-scottb
Comment 8 by scottb@google.com, Aug 13, 2008
1_5_RC2 has been released.
Status: Fixed
Sign in to add a comment