Skip to content

Commit

Permalink
Enable some tests after J19 problems were fixed for J21
Browse files Browse the repository at this point in the history
Two test classes which had redundant default clauses for switch with
record patterns were copied from the java19 to the java21 directory and
the redundant clauses deactivated, i.e. the test now run as originally
intended. For older JDK versions, the old tests still stay active in
order to document the old state of affairs.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
  • Loading branch information
kriegaex committed Nov 5, 2023
1 parent f0c0088 commit 70f3c09
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ public aspect RecordPatternsPreview1ExhaustivenessAspect {
switch (pair) {
case Pair<I>(I i, C c) -> System.out.println("x");
case Pair<I>(I i, D d) -> System.out.println("y");
// TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed
// TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed.
// Fixed since Java 21, see features1921/java21/RecordPatternsPreview1ExhaustivenessAspect.aj.
default -> System.out.println("z");
}

switch (pair) {
case Pair<I>(C c, I i) -> System.out.println("a");
case Pair<I>(D d, C c) -> System.out.println("b");
case Pair<I>(D d1, D d2) -> System.out.println("c");
// TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed
// TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed.
// Fixed since Java 21, see features1921/java21/RecordPatternsPreview1ExhaustivenessAspect.aj.
default -> System.out.println("d");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ static void exhaustiveSwitch() {
switch (p2) {
case Pair<I>(I i, C c) -> System.out.println("x");
case Pair<I>(I i, D d) -> System.out.println("y");
// TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed
// TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed.
// Fixed since Java 21, see features1921/java21/RecordPatternsPreview1ExhaustivenessOK1.java.
default -> System.out.println("z");
}

switch (p2) {
case Pair<I>(C c, I i) -> System.out.println("a");
case Pair<I>(D d, C c) -> System.out.println("b");
case Pair<I>(D d1, D d2) -> System.out.println("c");
// TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed
// TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed.
// Fixed since Java 21, see features1921/java21/RecordPatternsPreview1ExhaustivenessOK1.java.
default -> System.out.println("d");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public aspect RecordPatternsPreview1ExhaustivenessAspect {
static Pair<I> p2 = new Pair<>(new C(), new D());

public static void main(String[] args) {
doSomething(p2);
}

public static void doSomething(Pair<I> pair) {
System.out.println(pair.toString().replaceAll("@[0-9a-f]+", "@000"));
}

before(Pair<I> pair) : execution(* doSomething(Pair)) && args(pair) {
switch (pair) {
case Pair<I>(I i, C c) -> System.out.println("x");
case Pair<I>(I i, D d) -> System.out.println("y");
// Redundant default clause no longer necessary after fix of https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455.
// Old version with default clause see features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj.
// default -> System.out.println("z");
}

switch (pair) {
case Pair<I>(C c, I i) -> System.out.println("a");
case Pair<I>(D d, C c) -> System.out.println("b");
case Pair<I>(D d1, D d2) -> System.out.println("c");
// Redundant default clause no longer necessary after fix of https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455.
// Old version with default clause see features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj.
// default -> System.out.println("d");
}
}
}

sealed interface I permits C, D { }
final class C implements I { }
final class D implements I { }
record Pair<T>(T x, T y) { }
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ public void testRecordPatternsPreview1Error() {
}

public void testRecordPatternsPreview1ExhaustivenessOK1() {
// Falsely throws 'An enhanced switch statement should be exhaustive; a default label expected' twice,
// see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455
// TODO: Remove redundant default clauses when fixed upstream
System.out.println("TODO: fully activate when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed");
// Used to falsely throw 'An enhanced switch statement should be exhaustive; a default label expected' twice,
// see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455. Fixed in Java 21.
runTest("record patterns exhaustiveness 1");
}

Expand All @@ -71,10 +69,8 @@ public void testRecordPatternsPreview1Aspect() {
}

public void testRecordPatternsPreview1ExhaustivenessAspect() {
// Falsely throws 'An enhanced switch statement should be exhaustive; a default label expected' twice,
// see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455
// TODO: Remove redundant default clauses when fixed upstream
System.out.println("TODO: fully activate when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed");
// Used to falsely throw 'An enhanced switch statement should be exhaustive; a default label expected' twice,
// see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455. Fixed in Java 21.
runTest("record patterns exhaustiveness aspect");
}

Expand All @@ -84,11 +80,9 @@ public void testRecordPatternsPreview1ExhaustivenessError() {
}

public void testRecordPatternsPreview1ExhaustivenessOK2() {
// Falsely throws 'An enhanced switch statement should be exhaustive; a default label expected',
// see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/398
// TODO: activate when fixed
System.out.println("TODO: activate when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/398 has been fixed");
//runTest("record patterns exhaustiveness 2");
// Used to falsely throw 'An enhanced switch statement should be exhaustive; a default label expected',
// see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/398. Fixed in Java 21.
runTest("record patterns exhaustiveness 2");
}

public static Test suite() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
</ajc-test>

<!-- Java 21 final, Java 19, 20 preview -->
<ajc-test dir="features1919/java19" vm="21" title="record patterns exhaustiveness 1">
<ajc-test dir="features1921/java21" vm="21" title="record patterns exhaustiveness 1">
<compile files="RecordPatternsPreview1ExhaustivenessOK1.java" options="-21"/>
<run class="RecordPatternsPreview1ExhaustivenessOK1" vmargs="">
<stdout>
Expand All @@ -150,9 +150,8 @@
</ajc-test>

<!-- Java 21 final, Java 19, 20 preview -->
<ajc-test dir="features1919/java19" vm="21" title="record patterns exhaustiveness aspect">
<ajc-test dir="features1921/java21" vm="21" title="record patterns exhaustiveness aspect">
<compile files="RecordPatternsPreview1ExhaustivenessAspect.aj" options="-21"/>
<!-- TODO: Remove redundant default clauses when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed -->
<run class="RecordPatternsPreview1ExhaustivenessAspect" vmargs="">
<stdout>
<line text="y"/>
Expand Down

0 comments on commit 70f3c09

Please sign in to comment.