RFR: JDK-8223305: Compiler support for Switch Expressions

Jan Lahoda jan.lahoda at oracle.com
Tue May 28 09:37:11 UTC 2019


On 28. 05. 19 11:11, Maurizio Cimadamore wrote:
> Looks good. Just few comments/questions:

Thanks!

> 
> * I think the error keys in compiler.properties could use some renaming. 
> e.g.
> 
> compiler.err.break.complex.value.no.switch.expression -> 
> compiler.err.no.switch.expression
> compiler.err.break.complex.value.no.switch.expression.qualify -> 
> compiler.err.no.switch.expression.qualify

Sure, will do.

> 
> * what is the new Log.hasErrorOn - and why has Flow been changed to use it?

Consider code like this:
---
public class Y2 {
     private void t() {
         break;
     }
}
---

When compiled like this:
javac -XDdev -XDshould-stop.at=FLOW Y2.java

It will crash:
---
Y2.java:4: error: break outside switch or loop
              break;
              ^
1 error
An exception has occurred in the compiler (11.0.3). Please file a bug 
against the Java compiler via the Java bug reporting page 
(http://bugreport.java.com) after checking the Bug Database 
(http://bugs.java.com) for duplicates. Include your program and the 
following diagnostic in your report. Thank you.
java.lang.AssertionError
         at 
jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
         at 
jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
         at 
jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitMethodDef(Flow.java:518)
         at 
jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
         at 
jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
         at 
jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
         at 
jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitClassDef(Flow.java:488)
         at 
jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
         at 
jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
         at 
jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
         at 
jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.analyzeTree(Flow.java:759)
         at 
jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.analyzeTree(Flow.java:751)
         at 
jdk.compiler/com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:216)
         at 
jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1401)
         at 
jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1375)
         at 
jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
         at 
jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
         at 
jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
         at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
         at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
---

The reason is that javac asserts that it has properly processed the 
exits - but here the original code is broken, and an error has already 
been reported and this given spot, so it seems safe to not crash javac here.

Thanks,
     Jan

> 
> Thanks
> Maurizio
> 
> 
> It seems like a whitespace got remove here?
> 
> On 24/05/2019 15:48, Jan Lahoda wrote:
>> Hi,
>>
>> I'd like to ask for a review of changes to update javac to follow the 
>> current spec for switch expressions, in particular the break -> yield 
>> change:
>> http://cr.openjdk.java.net/~gbierman/jep354-jls-20190524.html
>>
>> Webrev:
>> http://cr.openjdk.java.net/~jlahoda/8223303/webrev.00/
>>
>> JBS:
>> https://bugs.openjdk.java.net/browse/JDK-8223305
>>
>> Feedback is welcome!
>>
>> Thanks,
>>    Jan


More information about the compiler-dev mailing list