Skip to content

Commit

Permalink
Regression test for #3109
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-sankaran authored Oct 18, 2024
1 parent 3e287dc commit bd799ad
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
import junit.framework.Test;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;

public class SwitchPatternTest21 extends AbstractBatchCompilerTest {
public class SwitchPatternTest22 extends AbstractBatchCompilerTest {

static {
// TESTS_NAMES = new String [] { "testNaming" };
}

public static Test suite() {
return buildMinimalComplianceTestSuite(SwitchPatternTest21.class, F_22);
return buildMinimalComplianceTestSuite(SwitchPatternTest22.class, F_22);
}

public SwitchPatternTest21(String name) {
public SwitchPatternTest22(String name) {
super(name);
}

Expand Down Expand Up @@ -956,4 +956,44 @@ public static void main(String[] args) {
},
"A or B");
}

// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3109
// [Patterns] Mixed multiple pattern and when is not fully supported in switch expression
public void testIssue3109() {
runConformTest(
new String[] {
"Maybe.java",
"""
import java.util.function.Function;
import java.util.function.Predicate;
public sealed interface Maybe<T> {
static <T> Maybe<T> of(T value) {
return new Some<>(value);
}
static <T> Maybe<T> empty() {
return new None<>();
}
default Maybe<T> filter(Predicate<T> predicate){
return switch (this) {
case Some(T value) when predicate.test(value) -> this; // unsupported line with 4 errors
case Some(_), None<T> _ -> empty();
};
}
default Maybe<T> filter2(Predicate<T> predicate){
return switch (this) {
case Some(_), None<T> _ -> empty(); //also unsupported with 1 error
};
}
record Some<T>(T value) implements Maybe<T> {}
record None<T>() implements Maybe<T>{}
}
"""
},
"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static Test suite() {
// since_22.add(SuperAfterStatementsTest.class);
since_22.add(UnnamedPatternsAndVariablesTest.class);
since_22.add(UseOfUnderscoreJava22Test.class);
since_22.add(SwitchPatternTest21.class);
since_22.add(SwitchPatternTest22.class);

ArrayList since_23 = new ArrayList();
since_23.add(SuperAfterStatementsTest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static Class[] getAllTestClasses() {
ASTRewritingInstanceOfPatternExpressionTest.class,
ASTRewritingSwitchPatternTest.class,
ResolveTests12To15.class,
SwitchPatternTest21.class,
SwitchPatternTest22.class,
JavaSearchBugs19Tests.class,
CompletionTestsForRecordPattern.class,
NullAnnotationTests21.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static Class[] getAllTestClasses() {
SealedTypesTests.class,
SealedTypesSpecReviewTest.class,
SwitchPatternTest.class,
SwitchPatternTest21.class,
SwitchPatternTest22.class,
UnnamedPatternsAndVariablesTest.class,
ASTRewritingTypeDeclTest.class,
ASTConverter_15Test.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.eclipse.jdt.core.tests.compiler.regression.RecordPatternTest;
import org.eclipse.jdt.core.tests.compiler.regression.SwitchExpressionsYieldTest;
import org.eclipse.jdt.core.tests.compiler.regression.SwitchPatternTest;
import org.eclipse.jdt.core.tests.compiler.regression.SwitchPatternTest21;
import org.eclipse.jdt.core.tests.compiler.regression.SwitchPatternTest22;
import org.eclipse.jdt.core.tests.compiler.regression.SwitchTest;
import org.eclipse.jdt.core.tests.compiler.regression.UnnamedPatternsAndVariablesTest;
import org.eclipse.jdt.core.tests.dom.ConverterTestSetup;
Expand All @@ -44,7 +44,7 @@ public static Class[] getAllTestClasses() {
return new Class[] {

SwitchPatternTest.class,
SwitchPatternTest21.class,
SwitchPatternTest22.class,
SwitchTest.class,
SwitchExpressionsYieldTest.class,

Expand Down

0 comments on commit bd799ad

Please sign in to comment.