IDEA-300124: highlight raw deconstruction patterns

GitOrigin-RevId: 8c5c34e21d9952a67b880868fe3ac600f058c582
This commit is contained in:
Alexandr Suhinin
2022-08-24 12:34:48 +03:00
committed by intellij-monorepo-bot
parent 550471e65e
commit db97df0ad1
4 changed files with 22 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
record Top(Child c1, Child c2) {}
record Child(I x, I y){}
record Wrong(int x) {}
record TypedRecord<T>(T t) {}
sealed interface I permits A, B {}
final class A implements I {}
@@ -18,6 +19,13 @@ public class Test {
}
}
<T> void testRawDeconstruction(TypedRecord<T> r) {
if (r instanceof TypedRecord<T>(I t)){ }
if (r instanceof TypedRecord<T>(T t)){ }
if (r instanceof <error descr="Raw deconstruction patterns are not allowed">TypedRecord</error>(I t)){ }
if (r instanceof <error descr="Raw deconstruction patterns are not allowed">TypedRecord</error>(T t)){ }
}
void resolveHighlighting1(Object o){
if (o instanceof Child(A a, B b) c){
System.out.println(a);

View File

@@ -40,6 +40,11 @@ public class Incompatible {
case TypedRecord<I>(I x) s-> {}
default -> {}
}
switch (typedRecord){
case <error descr="Raw deconstruction patterns are not allowed">TypedRecord</error>(C x) s-> {}
case <error descr="Raw deconstruction patterns are not allowed">TypedRecord</error>(I x) s-> {}
default -> {}
}
switch (object){
case Top(Child c1, Child(I x, <error descr="Incompatible types. Found: 'int', required: 'I'">int y</error>) c3) c -> { }
case Top(Child c1, <error descr="Incompatible types. Found: 'Wrong', required: 'Child'">Wrong(int y) c3</error>) c -> { }