mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
8312163: Crash in dominance check when compiling unnamed patterns
Reviewed-by: jlahoda
This commit is contained in:
committed by
Jan Lahoda
parent
b20dc1e9cd
commit
1fc726a8b3
@@ -4733,10 +4733,13 @@ public class Check {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (currentPattern instanceof JCBindingPattern) {
|
||||
return existingPattern instanceof JCBindingPattern;
|
||||
if (currentPattern instanceof JCBindingPattern ||
|
||||
currentPattern instanceof JCAnyPattern) {
|
||||
return existingPattern instanceof JCBindingPattern ||
|
||||
existingPattern instanceof JCAnyPattern;
|
||||
} else if (currentPattern instanceof JCRecordPattern currentRecordPattern) {
|
||||
if (existingPattern instanceof JCBindingPattern) {
|
||||
if (existingPattern instanceof JCBindingPattern ||
|
||||
existingPattern instanceof JCAnyPattern) {
|
||||
return true;
|
||||
} else if (existingPattern instanceof JCRecordPattern existingRecordPattern) {
|
||||
List<JCPattern> existingNested = existingRecordPattern.nested;
|
||||
|
||||
@@ -879,6 +879,7 @@ public class JavacParser implements Parser {
|
||||
JCExpression e;
|
||||
if (token.kind == UNDERSCORE && parsedType == null) {
|
||||
nextToken();
|
||||
checkSourceLevel(Feature.UNNAMED_VARIABLES);
|
||||
pattern = toP(F.at(token.pos).AnyPattern());
|
||||
}
|
||||
else {
|
||||
|
||||
57
test/langtools/tools/javac/T8312163.java
Normal file
57
test/langtools/tools/javac/T8312163.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8312163
|
||||
* @summary Crash in dominance check when compiling unnamed patterns
|
||||
* @enablePreview
|
||||
* @compile/fail/ref=T8312163.out -XDrawDiagnostics T8312163.java
|
||||
*/
|
||||
public class T8312163 {
|
||||
sealed interface A permits B {}
|
||||
record B() implements A {}
|
||||
|
||||
record Rec(A a, A b) {}
|
||||
|
||||
public void test(Rec r)
|
||||
{
|
||||
switch (r) {
|
||||
case Rec(_, _): break;
|
||||
case Rec(_, B()): // dominated
|
||||
}
|
||||
|
||||
switch (r) {
|
||||
case Rec(_, B()): break;
|
||||
case Rec(_, _):
|
||||
}
|
||||
|
||||
switch (r) {
|
||||
case Rec(_, _): break;
|
||||
case Rec(_, A a): // dominated
|
||||
}
|
||||
|
||||
switch (r) {
|
||||
case Rec(_, A a): break;
|
||||
case Rec(_, _): // dominated
|
||||
}
|
||||
|
||||
// duplicated unnamed patterns with unnamed pattern variables for reference
|
||||
switch (r) {
|
||||
case Rec(var _, var _): break;
|
||||
case Rec(var _, B()): // dominated
|
||||
}
|
||||
|
||||
switch (r) {
|
||||
case Rec(var _, B()): break;
|
||||
case Rec(var _, var _):
|
||||
}
|
||||
|
||||
switch (r) {
|
||||
case Rec(var _, var _): break;
|
||||
case Rec(var _, A a): // dominated
|
||||
}
|
||||
|
||||
switch (r) {
|
||||
case Rec(var _, A a): break;
|
||||
case Rec(var _, var _): // dominated
|
||||
}
|
||||
}
|
||||
}
|
||||
9
test/langtools/tools/javac/T8312163.out
Normal file
9
test/langtools/tools/javac/T8312163.out
Normal file
@@ -0,0 +1,9 @@
|
||||
T8312163.java:18:18: compiler.err.pattern.dominated
|
||||
T8312163.java:28:18: compiler.err.pattern.dominated
|
||||
T8312163.java:33:18: compiler.err.pattern.dominated
|
||||
T8312163.java:39:18: compiler.err.pattern.dominated
|
||||
T8312163.java:49:18: compiler.err.pattern.dominated
|
||||
T8312163.java:54:18: compiler.err.pattern.dominated
|
||||
- compiler.note.preview.filename: T8312163.java, DEFAULT
|
||||
- compiler.note.preview.recompile
|
||||
6 errors
|
||||
Reference in New Issue
Block a user