diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index 2c735909a0894..acd85b7c9aff0 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -6025,6 +6025,19 @@ public void visitBindingPattern(JCBindingPattern that) { super.visitBindingPattern(that); } + @Override + public void visitRecordPattern(JCRecordPattern that) { + initTypeIfNeeded(that); + if (that.record == null) { + that.record = new ClassSymbol(0, TreeInfo.name(that.deconstructor), + that.type, syms.noSymbol); + } + if (that.fullComponentTypes == null) { + that.fullComponentTypes = List.nil(); + } + super.visitRecordPattern(that); + } + @Override public void visitNewClass(JCNewClass that) { if (that.constructor == null) { diff --git a/test/langtools/tools/javac/patterns/Exhaustiveness.java b/test/langtools/tools/javac/patterns/Exhaustiveness.java index 726bd1d9a2e9a..f8ee25f0d3267 100644 --- a/test/langtools/tools/javac/patterns/Exhaustiveness.java +++ b/test/langtools/tools/javac/patterns/Exhaustiveness.java @@ -23,7 +23,7 @@ /** * @test - * @bug 8262891 8268871 8274363 8281100 8294670 8311038 8311815 8325215 + * @bug 8262891 8268871 8274363 8281100 8294670 8311038 8311815 8325215 8333169 * @summary Check exhaustiveness of switches over sealed types. * @library /tools/lib * @modules jdk.compiler/com.sun.tools.javac.api @@ -2076,6 +2076,35 @@ static int r(R r) { """); } + @Test //JDK-8333169 + public void testFlowForNestedSwitch(Path base) throws Exception { + doTest(base, + new String[0], + """ + class Main { + + record A() {}; + + public static void main(String[] args) { + A a1 = new A(); + A a2 = new A(); + + String causesCompilationError = log( + switch(a1) { + case A() -> switch(a2) { + case A() -> "A"; + }; + } + ); + } + + static T log(T t) { + System.out.println("LOG: " + t); + return t; + } + }"""); + } + private void doTest(Path base, String[] libraryCode, String testCode, String... expectedErrors) throws IOException { doTest(base, libraryCode, testCode, false, expectedErrors); }