Skip to content

Commit 75cdac2

Browse files
"Internal inconsistency" Warning when mixing lambda expressions with bounded wildcards (eclipse-jdt#4892)
* Fixes eclipse-jdt#4891
1 parent d478cbe commit 75cdac2

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/BranchLabel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ private boolean compatibleOperandStacks(OperandStack stackNow, OperandStack stac
134134
return false;
135135
int depth = 0;
136136
for (int i = 0, size = stackNow.size(); i < size; i++) {
137-
TypeBinding tn = stackNow.get(i);
138-
TypeBinding te = stackEarlier.get(i);
137+
TypeBinding tn = stackNow.get(i).erasure();
138+
TypeBinding te = stackEarlier.get(i).erasure();
139139
if (TypeBinding.notEquals(tn, te)) {
140140
if (!tn.isCompatibleWith(te) && !te.isCompatibleWith(tn)) {
141141
if (this.codeStream.classFile.referenceBinding.scope.lowerUpperBound(new TypeBinding[] {te, tn}) == null)

org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.jdt.core.tests.compiler;singleton:=true
5-
Bundle-Version: 3.13.1100.qualifier
5+
Bundle-Version: 3.13.1200.qualifier
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
88
Export-Package: org.eclipse.jdt.core.tests.compiler,

org.eclipse.jdt.core.tests.compiler/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<relativePath>../tests-pom/</relativePath>
2020
</parent>
2121
<artifactId>org.eclipse.jdt.core.tests.compiler</artifactId>
22-
<version>3.13.1100-SNAPSHOT</version>
22+
<version>3.13.1200-SNAPSHOT</version>
2323
<packaging>eclipse-test-plugin</packaging>
2424

2525
<properties>

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7076,5 +7076,47 @@ public static <T> List<?> get(List<T> l) {
70767076
},
70777077
"");
70787078
}
7079+
7080+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4891
7081+
// "Internal inconsistency" Warning when mixing lambda expressions with bounded wildcards
7082+
public void testIssue4891() {
7083+
if (this.complianceLevel < ClassFileConstants.JDK22)
7084+
return;
7085+
7086+
Runner runner = new Runner();
7087+
runner.expectedOutputString =
7088+
"Compiled and ran fine!";
7089+
runner.expectedCompilerLog = "";
7090+
7091+
runner.testFiles = new String[] {
7092+
"Bug.java",
7093+
"""
7094+
import java.util.function.Predicate;
7095+
7096+
// Internal inconsistency: Inappropriate operand stack size encountered during translation
7097+
public class Bug<T>{
7098+
7099+
static class Builder<T>{
7100+
Predicate<? super T> p;
7101+
}
7102+
7103+
final Predicate<? super T> p;
7104+
7105+
Bug(Builder<T> builder) {
7106+
this.p=builder.p==null?_->true:builder.p; //<-- caused by this line
7107+
// does not happen if passing predicate directly as argument
7108+
// does not happen without generic bounds <T>
7109+
// does not happen without ternary expression
7110+
// does not happen with unbounded wildcard <?>
7111+
}
7112+
7113+
public static void main(String [] args) {
7114+
System.out.println("Compiled and ran fine!");
7115+
}
7116+
}
7117+
"""
7118+
};
7119+
runner.runConformTest();
7120+
}
70797121
}
70807122

0 commit comments

Comments
 (0)