record PrimitiveAndSealed(int x, I y) {} record NormalAndSealed(Integer x, I y) {} sealed interface Super permits SuperChild, SuperRecord {} final class SuperChild implements Super {} record SuperRecord(I i) implements Super {} record Generic(T x) {} class A {} class B extends A {} sealed interface I permits C, D {} final class C implements I {} final class D implements I {} record Pair(T x, T y) {} record Top(Child c1, Child c2) {} record Child(I x, I y){} class Basic { String o; Super superInterface; SuperRecord superRecord; PrimitiveAndSealed primitiveAndSealed; NormalAndSealed normalAndSealed; Generic genericInterface; Generic genericC; void testGenerics(T p, Pair pair1, Pair pair2) { switch (p) { case SuperChild superChild -> {} case SuperRecord(C i) -> {} case SuperRecord(D i) -> {} } switch(p) { case SuperChild sc -> {} case SuperRecord sr -> {} } switch (pair1.x()) { case SuperChild sc -> {} case SuperRecord sr -> {} } switch (pair2.x()) { case SuperChild sc -> {} case SuperRecord sr -> {} } } void test(){ switch (superInterface) { //completed sealed with record case SuperChild superChild -> {} case SuperRecord(C i) -> {} case SuperRecord(D i) -> {} } switch (superInterface) { case SuperChild superChild -> {} case SuperRecord(C i) -> {} case SuperRecord(I i) -> {} } switch (superInterface) { case SuperChild superChild -> {} case SuperRecord(C i) -> {} case SuperRecord(I i) when i.hashCode() > 0 -> {} } switch (o) { //non-record is completed case String o -> {} } switch (superRecord) { case SuperRecord(C i) -> {} } switch (superRecord) { case SuperRecord(I i) -> {} } switch (primitiveAndSealed){ //error case PrimitiveAndSealed(int x, C y) -> {} } switch (primitiveAndSealed){ case PrimitiveAndSealed(int x, I y) -> {} } switch (primitiveAndSealed){ case PrimitiveAndSealed(int x, C y) -> {} case PrimitiveAndSealed(int x, D y) -> {} } switch (normalAndSealed){ //error case NormalAndSealed(Integer x, C y) -> {} } switch (normalAndSealed){ case NormalAndSealed(Integer x, I y) -> {} } switch (normalAndSealed){ case NormalAndSealed(Integer x, C y) -> {} case NormalAndSealed(Integer x, D y) -> {} } switch (genericInterface) { case Generic(I i) -> {} } switch (genericInterface) { case Generic(C i) -> {} } switch (genericInterface) { case Generic(C i) -> {} case Generic(D i) -> {} } switch (genericC) { case Generic(C i) -> {} } } void testNested(Top t){ switch (t){ case Top(Child(I x1, C y1), Child(C x2, I y2)) -> {} case Top(Child(I x1, D y1) , Child(I x2, C y2)) -> {} } switch (t){ case Top(Child(I x1, C y1) , Child c2) -> {} case Top(Child(I x1, D y1) , Child c2) -> {} } switch (t){ case Top(Child(I x1, C y1) , Child(I x2, I y2) ) -> {} case Top(Child(I x1, D y1) , Child(I x2, I y2) ) -> {} } switch (t){ case Top(Child c1, Child(C x2, I y2) ) -> {} case Top(Child c1, Child(I x2, C y2) ) -> {} } switch (t){ case Top(Child(I x1, C y1) , Child(I x2, I y2) ) -> {} case Top(Child(C x1, I y1) , Child(I x2, I y2) ) -> {} } switch (t){ case Top(Child(I x1, I y1) , Child(I x2, I y2) ) -> {} } } void test(Pair pairA, Pair pairI) { switch (pairA) { // Error! case Pair(A a,B b) -> { } case Pair(B b,A a) -> { } } switch (pairI) { // Error! case Pair(C fst, D snd) -> {} case Pair(D fst, C snd) -> {} case Pair(I fst, C snd) -> {} } switch (pairI) { case Pair(I i,C c) -> { } case Pair(I i,D d) -> { } } switch (pairI) { case Pair(C c,C i) -> { } case Pair(C c,D i) -> { } case Pair(D d,C c) -> { } case Pair(D d,D d2) -> { } } switch (pairI) { case Pair(C c,I i) -> { } case Pair(D d,C c) -> { } case Pair(D d,D d2) -> { } } switch(pairI.x()) { case C c when true -> {} case D d -> {} } } record R(int x) { } void emptyRecord(R r) { switch (r) { //error } } void emptyRecord2(R r) { switch (r) { //error case null -> System.out.println("1"); } } void emptyRecord3(R r) { switch (r) { //error case R r2 when r2.x() == 1 -> System.out.println("1"); } } void emptyInteger(int i) { switch (i) { } } void emptyObject0(Object o) { switch (o) { //error } } void emptyObject(Object o) { switch (o) { //error case null -> System.out.println(1); } } void emptyObject2(Object o) { switch (o) { case String s when s.length()==1 -> System.out.println(1); } } void emptyRecord4(R r) { switch (r) { case R r2 when r2.x() == 1 -> System.out.println(1); case R r2 -> System.out.println("1"); } } void emptyRecord5(R r) { switch (r) { //error case R r2 when r2.x() == 1 -> System.out.println(1); } } void emptyRecord6(R r) { switch (r) { default -> System.out.println("1"); } } void exhaustinvenessWithInterface(Pair pairI) { switch (pairI) { case Pair(C fst, D snd) -> {} case Pair(I fst, C snd) -> {} case Pair(D fst, I snd) -> {} } } void exhaustinvenessWithInterface2(Pair pairI) { switch (pairI) { case Pair(C fst, D snd) -> {} case Pair(I fst, C snd) -> {} case Pair(D fst, I snd) -> {} } } }