# HG changeset patch # User jlahoda # Date 1574944911 -3600 # Thu Nov 28 13:41:51 2019 +0100 # Node ID fb008576335f79d490a9dbc7690f7834843998a1 # Parent 7799a51dbe30736ca12e007af5ba96a7bb610010 [mq]: 8234922 diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java @@ -280,8 +280,7 @@ //related errors, which will allow for more errors to be detected Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); try { - boolean[] breaksOut = new boolean[1]; - SnippetBreakAnalyzer analyzer = new SnippetBreakAnalyzer(loop); + SnippetBreakAnalyzer analyzer = new SnippetBreakAnalyzer(); analyzer.analyzeTree(env, body, make); return analyzer.breaksOut(); @@ -1515,16 +1514,22 @@ } class SnippetBreakAnalyzer extends AliveAnalyzer { - private final JCTree loop; + private final Set seenTrees = new HashSet<>(); private boolean breaksOut; - public SnippetBreakAnalyzer(JCTree loop) { - this.loop = loop; + public SnippetBreakAnalyzer() { + } + + @Override + public void scan(JCTree tree) { + seenTrees.add(tree); + super.scan(tree); } @Override public void visitBreak(JCBreak tree) { - breaksOut |= (super.alive == Liveness.ALIVE && tree.target == loop); + breaksOut |= (super.alive == Liveness.ALIVE && + !seenTrees.contains(tree.target)); super.visitBreak(tree); } diff --git a/test/langtools/tools/javac/patterns/BindingsTest1.java b/test/langtools/tools/javac/patterns/BindingsTest1.java --- a/test/langtools/tools/javac/patterns/BindingsTest1.java +++ b/test/langtools/tools/javac/patterns/BindingsTest1.java @@ -146,6 +146,30 @@ s.length(); } + { + while (!(o1 instanceof String s)) { + L8: break L8; + } + + s.length(); + } + + { + for ( ;!(o1 instanceof String s); ) { + L9: break L9; + } + + s.length(); + } + + { + do { + L10: break L10; + } while (!(o1 instanceof String s)); + + s.length(); + } + if (o1 instanceof String s) { Runnable r1 = new Runnable() { @Override diff --git a/test/langtools/tools/javac/patterns/BindingsTest2.java b/test/langtools/tools/javac/patterns/BindingsTest2.java --- a/test/langtools/tools/javac/patterns/BindingsTest2.java +++ b/test/langtools/tools/javac/patterns/BindingsTest2.java @@ -187,5 +187,59 @@ s.length(); } + + { + L: while (!(o1 instanceof String s)) { + break L; + } + + s.length(); + } + + { + L: for (; !(o1 instanceof String s); ) { + break L; + } + + s.length(); + } + + { + L: do { + break L; + } while (!(o1 instanceof String s)); + + s.length(); + } + + { + L: { + while (!(o1 instanceof String s)) { + break L; + } + + s.length(); + } + } + + { + L: { + for (; !(o1 instanceof String s); ) { + break L; + } + + s.length(); + } + } + + { + L: { + do { + break L; + } while (!(o1 instanceof String s)); + + s.length(); + } + } } } diff --git a/test/langtools/tools/javac/patterns/BindingsTest2.out b/test/langtools/tools/javac/patterns/BindingsTest2.out --- a/test/langtools/tools/javac/patterns/BindingsTest2.out +++ b/test/langtools/tools/javac/patterns/BindingsTest2.out @@ -40,9 +40,15 @@ BindingsTest2.java:154:13: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) BindingsTest2.java:171:13: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) BindingsTest2.java:179:13: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) +BindingsTest2.java:196:13: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) +BindingsTest2.java:204:13: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) +BindingsTest2.java:212:13: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) +BindingsTest2.java:221:17: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) +BindingsTest2.java:231:17: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) +BindingsTest2.java:241:17: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) BindingsTest2.java:135:17: compiler.err.unreachable.stmt BindingsTest2.java:160:17: compiler.err.unreachable.stmt BindingsTest2.java:185:17: compiler.err.unreachable.stmt - compiler.note.preview.filename: BindingsTest2.java - compiler.note.preview.recompile -45 errors \ No newline at end of file +51 errors \ No newline at end of file