Skip to content

Commit 70f3c09

Browse files
committed
Enable some tests after J19 problems were fixed for J21
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 <[email protected]>
1 parent f0c0088 commit 70f3c09

File tree

5 files changed

+52
-20
lines changed

5 files changed

+52
-20
lines changed

tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ public aspect RecordPatternsPreview1ExhaustivenessAspect {
1313
switch (pair) {
1414
case Pair<I>(I i, C c) -> System.out.println("x");
1515
case Pair<I>(I i, D d) -> System.out.println("y");
16-
// TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed
16+
// TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed.
17+
// Fixed since Java 21, see features1921/java21/RecordPatternsPreview1ExhaustivenessAspect.aj.
1718
default -> System.out.println("z");
1819
}
1920

2021
switch (pair) {
2122
case Pair<I>(C c, I i) -> System.out.println("a");
2223
case Pair<I>(D d, C c) -> System.out.println("b");
2324
case Pair<I>(D d1, D d2) -> System.out.println("c");
24-
// TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed
25+
// TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed.
26+
// Fixed since Java 21, see features1921/java21/RecordPatternsPreview1ExhaustivenessAspect.aj.
2527
default -> System.out.println("d");
2628
}
2729
}

tests/features1919/java19/RecordPatternsPreview1ExhaustivenessOK1.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ static void exhaustiveSwitch() {
1010
switch (p2) {
1111
case Pair<I>(I i, C c) -> System.out.println("x");
1212
case Pair<I>(I i, D d) -> System.out.println("y");
13-
// TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed
13+
// TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed.
14+
// Fixed since Java 21, see features1921/java21/RecordPatternsPreview1ExhaustivenessOK1.java.
1415
default -> System.out.println("z");
1516
}
1617

1718
switch (p2) {
1819
case Pair<I>(C c, I i) -> System.out.println("a");
1920
case Pair<I>(D d, C c) -> System.out.println("b");
2021
case Pair<I>(D d1, D d2) -> System.out.println("c");
21-
// TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed
22+
// TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed.
23+
// Fixed since Java 21, see features1921/java21/RecordPatternsPreview1ExhaustivenessOK1.java.
2224
default -> System.out.println("d");
2325
}
2426
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
public aspect RecordPatternsPreview1ExhaustivenessAspect {
2+
static Pair<I> p2 = new Pair<>(new C(), new D());
3+
4+
public static void main(String[] args) {
5+
doSomething(p2);
6+
}
7+
8+
public static void doSomething(Pair<I> pair) {
9+
System.out.println(pair.toString().replaceAll("@[0-9a-f]+", "@000"));
10+
}
11+
12+
before(Pair<I> pair) : execution(* doSomething(Pair)) && args(pair) {
13+
switch (pair) {
14+
case Pair<I>(I i, C c) -> System.out.println("x");
15+
case Pair<I>(I i, D d) -> System.out.println("y");
16+
// Redundant default clause no longer necessary after fix of https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455.
17+
// Old version with default clause see features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj.
18+
// default -> System.out.println("z");
19+
}
20+
21+
switch (pair) {
22+
case Pair<I>(C c, I i) -> System.out.println("a");
23+
case Pair<I>(D d, C c) -> System.out.println("b");
24+
case Pair<I>(D d1, D d2) -> System.out.println("c");
25+
// Redundant default clause no longer necessary after fix of https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455.
26+
// Old version with default clause see features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj.
27+
// default -> System.out.println("d");
28+
}
29+
}
30+
}
31+
32+
sealed interface I permits C, D { }
33+
final class C implements I { }
34+
final class D implements I { }
35+
record Pair<T>(T x, T y) { }

tests/src/test/java/org/aspectj/systemtest/ajc1921/Ajc1921TestsJava.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ public void testRecordPatternsPreview1Error() {
5959
}
6060

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

@@ -71,10 +69,8 @@ public void testRecordPatternsPreview1Aspect() {
7169
}
7270

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

@@ -84,11 +80,9 @@ public void testRecordPatternsPreview1ExhaustivenessError() {
8480
}
8581

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

9488
public static Test suite() {

tests/src/test/resources/org/aspectj/systemtest/ajc1921/ajc1921.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
</ajc-test>
140140

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

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

0 commit comments

Comments
 (0)