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){} public class Basic { String o; Super superInterface; SuperRecord superRecord; PrimitiveAndSealed primitiveAndSealed; NormalAndSealed normalAndSealed; Generic genericInterface; Generic genericC; 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) r 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) c1, Child(C x2, I y2) c2) -> {} case Top(Child(I x1, D y1) c1, Child(I x2, C y2) c2) -> {} } switch (t){ case Top(Child(I x1, C y1) c1, Child c2) -> {} case Top(Child(I x1, D y1) c1, Child c2) -> {} } switch (t){ case Top(Child(I x1, C y1) c1, Child(I x2, I y2) c2) -> {} case Top(Child(I x1, D y1) c1, Child(I x2, I y2) c2) -> {} } switch (t){ case Top(Child c1, Child(C x2, I y2) c2) -> {} case Top(Child c1, Child(I x2, C y2) c2) -> {} } switch (t){ case Top(Child(I x1, C y1) c1, Child(I x2, I y2) c2) -> {} case Top(Child(C x1, I y1) c1, Child(I x2, I y2) c2) -> {} } switch (t){ case Top(Child(I x1, I y1) c1, Child(I x2, I y2) c2) -> {} } } 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) -> { } } } }