Skip to content

Commit

Permalink
Fixes eclipse-jdt#587 [pattern switch] Parameterized Type check in ex…
Browse files Browse the repository at this point in the history
…haustiveness (eclipse-jdt#1292)
  • Loading branch information
mpalat authored Aug 16, 2023
1 parent 36a1928 commit 656af65
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,16 @@ public ReferenceBinding[] permittedTypes() {
ReferenceBinding[] permTypes = this.type.permittedTypes();
List<ReferenceBinding> applicablePermTypes = new ArrayList<>();
for (ReferenceBinding pt : permTypes) {
if (pt.isCompatibleWith(this))
ReferenceBinding permittedTypeAvatar = pt;
if (pt.isRawType()) {
ReferenceBinding ptRef = pt.actualType();
// don't use TypeSystem.getParameterizedType below as this is just for temporary check.
ParameterizedTypeBinding ptb = new ParameterizedTypeBinding(ptRef, this.arguments, ptRef.enclosingType(), this.environment);
ptb.superclass();
ptb.superInterfaces();
permittedTypeAvatar = ptb;
}
if (permittedTypeAvatar.isCompatibleWith(this))
applicablePermTypes.add(pt);
}
return applicablePermTypes.toArray(new ReferenceBinding[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SwitchPatternTest extends AbstractRegressionTest9 {
static {
// TESTS_NUMBERS = new int [] { 40 };
// TESTS_RANGE = new int[] { 1, -1 };
// TESTS_NAMES = new String[] { "testRecPatExhaust"};
// TESTS_NAMES = new String[] { "testIssue587_001"};
}

private static String previewLevel = "21";
Expand Down Expand Up @@ -6228,4 +6228,26 @@ public void testIssue1126b() {
"1\n" +
"0");
}
public void testIssue587_001() {
runConformTest(
new String[] {
"X.java",
"public class X {\n"+
" sealed interface I<T> permits A, B {}\n"+
" final static class A<T> implements I<String> {}\n"+
" final static class B<Y> implements I<Y> {}\n"+
"\n"+
" static int testGenericSealedExhaustive(I<Integer> i) {\n"+
" return switch (i) {\n"+
" // Exhaustive as no A case possible!\n"+
" case B<Integer> bi -> 42;\n"+
" };\n"+
" }\n"+
" public static void main(String[] args) {\n"+
" System.out.println(testGenericSealedExhaustive(new B<Integer>()));\n"+
" }\n"+
"}",
},
"42");
}
}

0 comments on commit 656af65

Please sign in to comment.