Skip to content

Commit 0933895

Browse files
Reduce b2 when reducing ConstraintExpressionFormula (#4315)
Fixes #4314 --------- Co-authored-by: Stephan Herrmann <[email protected]>
1 parent 0bd1cc0 commit 0933895

File tree

5 files changed

+98
-21
lines changed

5 files changed

+98
-21
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ public Object reduce(InferenceContext18 inferenceContext) throws InferenceFailur
132132
inferenceContext.inferenceKind = inferenceContext.getInferenceKind(previousMethod, argumentTypes);
133133
boolean isDiamond = method.isConstructor() && this.left.isPolyExpression(method);
134134
inferInvocationApplicability(inferenceContext, method, argumentTypes, isDiamond, inferenceContext.inferenceKind);
135+
try {
136+
CapturingContext.enter(invocation.sourceStart(), invocation.sourceEnd(), inferenceContext.scope);
137+
if (!inferenceContext.reduce())
138+
return FALSE;
139+
} finally {
140+
CapturingContext.leave();
141+
}
135142
// b2 has been lifted, inferring poly invocation type amounts to lifting b3.
136143
}
137144
if (!inferenceContext.computeB3(invocation, this.right, method))

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ private boolean siSubI(TypeBinding si, TypeBinding funcI) {
10741074
/**
10751075
* JLS 18.2. reduce all initial constraints
10761076
*/
1077-
private boolean reduce() throws InferenceFailureException {
1077+
public boolean reduce() throws InferenceFailureException {
10781078
// Caution: This can be reentered recursively even as an earlier call is munching through the constraints !
10791079
for (int i = 0; this.initialConstraints != null && i < this.initialConstraints.length; i++) {
10801080
final ConstraintFormula currentConstraint = this.initialConstraints[i];

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,9 @@ Excuse excuseFor(JavacCompiler compiler) {
11801180
JavacBug8348928 = // https://bugs.openjdk.org/browse/JDK-8348928
11811181
new JavacHasABug(MismatchType.EclipseErrorsJavacWarnings),
11821182
JavacBug8348410 = // https://bugs.openjdk.org/browse/JDK-8348410
1183-
new JavacHasABug(MismatchType.EclipseErrorsJavacNone, ClassFileConstants.JDK25, 0000);
1183+
new JavacHasABug(MismatchType.EclipseErrorsJavacNone, ClassFileConstants.JDK25, 0000),
1184+
JavacBug8016196 = // https://bugs.openjdk.org/browse/JDK-8016196
1185+
new JavacHasABug(MismatchType.JavacErrorsEclipseNone);
11841186

11851187

11861188
// bugs that have been fixed but that we've not identified

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.Map;
4343
import junit.framework.Test;
4444
import org.eclipse.jdt.core.JavaCore;
45+
import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.JavacHasABug;
4546
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
4647
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
4748

@@ -6974,5 +6975,88 @@ protected void run() {
69746975
}
69756976
);
69766977
}
6978+
6979+
public void testGH4314() {
6980+
runConformTest(new String[] {
6981+
"Test.java",
6982+
"""
6983+
import java.util.function.Function;
6984+
6985+
public class Test {
6986+
6987+
public static void main(String[] args) {
6988+
m(
6989+
i -> new A<>(i),
6990+
b -> b.intValue());
6991+
}
6992+
6993+
private static <T, R> void m(Function<Integer, A<T>> f1, Function<T, R> f2) {}
6994+
private static class A<T> {
6995+
public A(T t) {}
6996+
}
6997+
}
6998+
"""
6999+
});
7000+
}
7001+
public void testGH4314b() {
7002+
if (this.complianceLevel < ClassFileConstants.JDK22)
7003+
return; // uses unnamed lambda param
7004+
Runner runner = new Runner();
7005+
runner.testFiles = new String[] {
7006+
"Test.java",
7007+
"""
7008+
import java.util.function.Function;
7009+
public class Test {
7010+
public static void main(String[] args) {
7011+
C<B<?>> c = null;
7012+
m(
7013+
_ -> new A<>(c),
7014+
b -> b.intValue());
7015+
}
7016+
static <T, R> void m(Function<B<Number>, A<T>> f1, Function<T, R> f2) {}
7017+
static class A<U> {
7018+
public A(C<? extends C<U>> t) {}
7019+
}
7020+
record B<V extends Number>(V t) implements C<V> {
7021+
7022+
}
7023+
interface C<W> {
7024+
W t();
7025+
}
7026+
}
7027+
"""
7028+
};
7029+
runner.javacTestOptions = JavacHasABug.JavacBug8016196;
7030+
runner.runConformTest();
7031+
}
7032+
public void testGH4314c() {
7033+
if (this.complianceLevel < ClassFileConstants.JDK22)
7034+
return; // uses unnamed lambda param
7035+
runConformTest(new String[] {
7036+
"Test.java",
7037+
"""
7038+
import java.util.function.Function;
7039+
public class Test {
7040+
public static void main(String[] args) {
7041+
C<B<?>> c = null;
7042+
m(
7043+
_ -> new A<>(c),
7044+
b -> b.intValue());
7045+
}
7046+
static <T, R> void m(Function<B<Number>, A<T>> f1, Function<T, R> f2) {}
7047+
static class A<U> {
7048+
public A(C<? extends C<? extends U>> t) {}
7049+
}
7050+
record B<V extends Number>(V t) implements C<V> {
7051+
7052+
}
7053+
interface C<W> {
7054+
W t();
7055+
}
7056+
}
7057+
"""
7058+
},
7059+
"");
7060+
}
69777061
}
69787062

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10581,33 +10581,17 @@ public void process() {
1058110581
"""
1058210582
},
1058310583
"----------\n" +
10584-
"1. ERROR in TestMe.java (at line 15)\n" +
10585-
" future = active.thenComposeAsync(recording -> {\n" +
10586-
" recording.stop().run();\n" +
10587-
"// This code (should) have compile errors but instead triggers ClassCastException\n" +
10588-
"\n" +
10589-
" return update().handleAsync(() -> recording.process());\n" +
10590-
"\n" +
10591-
"// Deleting the line and using this code would work\n" +
10592-
"// return update().handleAsync((a, b) -> {\n" +
10593-
"// recording.process();\n" +
10594-
"// return null;\n" +
10595-
"// });\n" +
10596-
" });\n" +
10597-
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
10598-
"Type mismatch: cannot convert from CompletableFuture<Object> to CompletableFuture<Void>\n" +
10599-
"----------\n" +
10600-
"2. ERROR in TestMe.java (at line 19)\n" +
10584+
"1. ERROR in TestMe.java (at line 19)\n" +
1060110585
" return update().handleAsync(() -> recording.process());\n" +
1060210586
" ^^^^^^^^^^^\n" +
1060310587
"The method handleAsync(BiFunction<? super capture#1-of ?,Throwable,? extends U>) in the type CompletableFuture<capture#1-of ?> is not applicable for the arguments (() -> {})\n" +
1060410588
"----------\n" +
10605-
"3. ERROR in TestMe.java (at line 19)\n" +
10589+
"2. ERROR in TestMe.java (at line 19)\n" +
1060610590
" return update().handleAsync(() -> recording.process());\n" +
1060710591
" ^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1060810592
"Lambda expression's signature does not match the signature of the functional interface method apply(? super capture#1-of ?, Throwable)\n" +
1060910593
"----------\n" +
10610-
"4. ERROR in TestMe.java (at line 19)\n" +
10594+
"3. ERROR in TestMe.java (at line 19)\n" +
1061110595
" return update().handleAsync(() -> recording.process());\n" +
1061210596
" ^^^^^^^^^^^^^^^^^^^\n" +
1061310597
"Cannot return a void result\n" +

0 commit comments

Comments
 (0)