8333169: javac NullPointerException record.type

Reviewed-by: vromero
This commit is contained in:
Jan Lahoda 2024-05-31 13:14:44 +00:00
parent e930bc1fbb
commit 32ee252c45
2 changed files with 43 additions and 1 deletions

View File

@ -6025,6 +6025,19 @@ public class Attr extends JCTree.Visitor {
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) {

View File

@ -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 @@ public class Exhaustiveness extends TestRunner {
""");
}
@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> 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);
}