mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
[java-highlighting] IDEA-324544 Support intersections for exhaustiveness
GitOrigin-RevId: c87035335aa16dd8ff50d903cc9de814fe7b6a30
This commit is contained in:
committed by
intellij-monorepo-bot
parent
56128f71f7
commit
cb3916ded4
@@ -1,3 +1,5 @@
|
||||
package com.test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
record LongRecord(String s1, String s2, String s3) {}
|
||||
@@ -14,7 +16,7 @@ final class D implements I {}
|
||||
|
||||
record TypedRecord<T>(T x) {}
|
||||
|
||||
class Incompatible {
|
||||
public class Incompatible {
|
||||
|
||||
Object object;
|
||||
Integer integer;
|
||||
@@ -23,29 +25,29 @@ class Incompatible {
|
||||
<T extends IntegerRecord> void incompatible() {
|
||||
switch (object) {
|
||||
case LongRecord<error descr="Incorrect number of nested patterns: expected 3 but found 2">(String s1, int y)</error> -> {}
|
||||
case RecordWithInterface<error descr="Incorrect number of nested patterns: expected 2 but found 1">(Integer y)</error> when true -> {}
|
||||
case RecordWithInterface(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'I'">Integer x</error>, D y) when true -> {}
|
||||
case RecordWithInterface(I x, D y) when true -> {}
|
||||
case RecordWithInterface<error descr="Incorrect number of nested patterns: expected 2 but found 1">(Integer y)</error> when true -> {}
|
||||
case RecordWithInterface(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'com.test.I'">Integer x</error>, D y) when true -> {}
|
||||
case RecordWithInterface(I x, D y) when true -> {}
|
||||
case <error descr="Deconstruction pattern can only be applied to a record, 'java.lang.Integer' is not a record">Integer</error>(double x) -> {}
|
||||
case PrimitiveRecord(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'int'">Integer x</error>) when true -> {}
|
||||
case PrimitiveRecord(int x) when true -> {}
|
||||
case IntegerRecord(Integer x) when true -> {}
|
||||
case IntegerRecord(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Integer'">int x</error>) when true -> {}
|
||||
case PrimitiveRecord(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'int'">Integer x</error>) when true -> {}
|
||||
case PrimitiveRecord(int x) when true -> {}
|
||||
case IntegerRecord(Integer x) when true -> {}
|
||||
case IntegerRecord(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Integer'">int x</error>) when true -> {}
|
||||
case <error descr="'Object' cannot be safely cast to 'T'">T(Integer x)</error> -> {}
|
||||
|
||||
}
|
||||
switch (integer){
|
||||
case <error descr="Incompatible types. Found: 'PrimitiveRecord', required: 'java.lang.Integer'">PrimitiveRecord(int x)</error> -> {}
|
||||
case <error descr="Incompatible types. Found: 'com.test.PrimitiveRecord', required: 'java.lang.Integer'">PrimitiveRecord(int x)</error> -> {}
|
||||
default -> {}
|
||||
}
|
||||
switch (typedRecord){
|
||||
case TypedRecord<I>(I x) -> {}
|
||||
case TypedRecord<I>(I x)-> {}
|
||||
default -> {}
|
||||
}
|
||||
switch (typedRecord){
|
||||
case TypedRecord(C x) -> {}
|
||||
case TypedRecord(I x) -> {}
|
||||
case TypedRecord<I>(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'I'">Integer t</error>) -> {}
|
||||
case TypedRecord(C x)-> {}
|
||||
case TypedRecord(I x)-> {}
|
||||
case TypedRecord<I>(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'com.test.I'">Integer t</error>) -> {}
|
||||
case TypedRecord<?>(<error descr="'Object' cannot be safely cast to 'List<Number>'">List<Number> nums</error>) -> {}
|
||||
case TypedRecord<?>(List<?> list) -> {}
|
||||
case TypedRecord<?>(<error descr="'Object' cannot be safely cast to 'T'">T t</error>) -> {}
|
||||
@@ -54,9 +56,9 @@ class Incompatible {
|
||||
default -> {}
|
||||
}
|
||||
switch (object){
|
||||
case Top(Child c1, Child(I x, <error descr="Incompatible types. Found: 'int', required: 'I'">int y</error>)) -> { }
|
||||
case Top(Child c1, <error descr="Incompatible types. Found: 'Wrong', required: 'Child'">Wrong(int y)</error>) -> { }
|
||||
case Top(Child c1, Child(C a, I i)) -> { }
|
||||
case Top(Child c1, Child(I x, <error descr="Incompatible types. Found: 'int', required: 'com.test.I'">int y</error>)) -> { }
|
||||
case Top(Child c1, <error descr="Incompatible types. Found: 'com.test.Wrong', required: 'com.test.Child'">Wrong(int y)</error>) -> { }
|
||||
case Top(Child c1, Child(C a, I i)) -> { }
|
||||
default -> {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,16 +145,16 @@ class Main {
|
||||
};
|
||||
|
||||
switch (ii) {
|
||||
case Object obj, <error descr="Invalid case label combination: 'null' can only be used as a single case label or paired only with 'default'">null</error>:
|
||||
case <error descr="'switch' has both an unconditional pattern and a default label">Object obj</error>:
|
||||
System.out.println("int");
|
||||
break;
|
||||
default:
|
||||
<error descr="'switch' has both an unconditional pattern and a default label">default</error>:
|
||||
System.out.println("def");
|
||||
break;
|
||||
}
|
||||
str = switch (ii) {
|
||||
case Object obj, <error descr="Invalid case label combination: 'null' can only be used as a single case label or paired only with 'default'">null</error> -> "int";
|
||||
default -> "def";
|
||||
case <error descr="'switch' has both an unconditional pattern and a default label">Object obj</error> -> "int";
|
||||
<error descr="'switch' has both an unconditional pattern and a default label">default</error> -> "def";
|
||||
};
|
||||
|
||||
switch (ii) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import java.util.Optional;
|
||||
|
||||
record PrimitiveAndSealed(int x, I y) {}
|
||||
record NormalAndSealed(Integer x, I y) {}
|
||||
|
||||
@@ -244,4 +246,35 @@ class Basic {
|
||||
case Pair<? extends I>(D fst, I snd) -> {}
|
||||
}
|
||||
}
|
||||
|
||||
sealed interface Parent {}
|
||||
record AAA() implements Parent {}
|
||||
record BBB() implements Parent {}
|
||||
|
||||
void test(Optional<? extends Parent> optional) {
|
||||
switch (optional.get()) {
|
||||
case AAA a -> {}
|
||||
case BBB b -> {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CCCC{}
|
||||
public <T extends CCCC & Comparable<T>> void test(T c) {
|
||||
switch (c) {
|
||||
case Comparable t -> System.out.println(13);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
interface II1{}
|
||||
sealed interface II2{}
|
||||
non-sealed class Cl1 implements II2{}
|
||||
public <T extends II1 & II2> void test(T c) {
|
||||
switch (c) {
|
||||
case Cl1 t:
|
||||
System.out.println(21);
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user