Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2019-02-21 19:29:45 -0500
committerStephan Herrmann2019-04-04 05:17:10 -0400
commitea6dff04b6decdc2a1f54bc692022a63221a6a0a (patch)
treec12e8188118a4ed4bc7238388060a3801180bdd3
parente999bb4ba9881dd2af02dc519fde9fa04b6abc48 (diff)
downloadeclipse.jdt.core-ea6dff04b6decdc2a1f54bc692022a63221a6a0a.tar.gz
eclipse.jdt.core-ea6dff04b6decdc2a1f54bc692022a63221a6a0a.tar.xz
eclipse.jdt.core-ea6dff04b6decdc2a1f54bc692022a63221a6a0a.zip
Bug 545082 - [1.8][inference] type variables βi from capture bounds must
not be considered for θ in §18.5.1 - the unrelated change in CaptureBinding18 fixes an obvious omission Change-Id: I0d7bb2b137799a747c5e82acd217b9b42c3a1826
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java43
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding18.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceSubstitution.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceVariable.java10
5 files changed, 55 insertions, 6 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
index e2fe76ef0e..4a3a0454b4 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
@@ -9585,4 +9585,47 @@ public void testBug508834_comment0() {
"}\n"
});
}
+ public void testBug545082a() {
+ Runner runner = new Runner();
+ runner.testFiles = new String[] {
+ "Test.java",
+ "import java.util.stream.Collectors;\n" +
+ "import java.util.stream.Stream;\n" +
+ "\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args)\n" +
+ " {\n" +
+ " println(Stream.of(42).collect(Collectors.summingDouble(d -> d))); \n" +
+ " }\n" +
+ " public static void println(double x) {}\n" +
+ " public static void println(char[] x) {}\n" +
+ " public static void println(String x) {}\n" +
+ " public static void println(Object x) {} \n" +
+ "}\n"
+ };
+ runner.runConformTest();
+ }
+ public void testBug545082b() {
+ Runner runner = new Runner();
+ runner.testFiles = new String[] {
+ "Test.java",
+ "import java.util.stream.Collectors;\n" +
+ "import java.util.stream.Stream;\n" +
+ "\n" +
+ "public class Test {\n" +
+ " char[] f;" +
+ " public void test() {\n" +
+ " f = Stream.of(42).collect(Collectors.summingDouble(d -> d)); \n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. ERROR in Test.java (at line 6)\n" +
+ " f = Stream.of(42).collect(Collectors.summingDouble(d -> d)); \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Type mismatch: cannot convert from Double to char[]\n" +
+ "----------\n";
+ runner.runNegativeTest();
+ }
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding18.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding18.java
index 447df46720..d00704bcfa 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding18.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding18.java
@@ -102,6 +102,8 @@ public class CaptureBinding18 extends CaptureBinding {
return erasures[0];
return this.environment.createIntersectionType18(erasures);
}
+ if (this.superclass == null)
+ return this.environment.getType(TypeConstants.JAVA_LANG_OBJECT);
return super.erasure();
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java
index 9775a90574..2fb1f91e80 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java
@@ -312,7 +312,7 @@ public class InferenceContext18 {
}
InferenceVariable[] newVariables = new InferenceVariable[len];
for (int i = 0; i < len; i++)
- newVariables[i] = InferenceVariable.get(typeVariables[i], i, this.currentInvocation, this.scope, this.object);
+ newVariables[i] = InferenceVariable.get(typeVariables[i], i, this.currentInvocation, this.scope, this.object, true);
addInferenceVariables(newVariables);
return newVariables;
}
@@ -340,7 +340,7 @@ public class InferenceContext18 {
newVariables[i] = (InferenceVariable) typeVariables[i]; // prevent double substitution of an already-substituted inferenceVariable
else
toAdd[numToAdd++] =
- newVariables[i] = InferenceVariable.get(typeVariables[i], i, this.currentInvocation, this.scope, this.object);
+ newVariables[i] = InferenceVariable.get(typeVariables[i], i, this.currentInvocation, this.scope, this.object, false);
}
if (numToAdd > 0) {
int start = 0;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceSubstitution.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceSubstitution.java
index ef0ac81f08..938bfec376 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceSubstitution.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceSubstitution.java
@@ -81,7 +81,7 @@ public class InferenceSubstitution extends Scope.Substitutor implements Substitu
public TypeBinding substitute(Substitution substitution, TypeBinding originalType) {
for (int i = 0; i < this.variables.length; i++) {
InferenceVariable variable = this.variables[i];
- if (isInSites(variable.site) && isSameParameter(getP(i), originalType)) {
+ if (variable.isFromInitialSubstitution && isInSites(variable.site) && isSameParameter(getP(i), originalType)) {
if (this.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled && originalType.hasNullTypeAnnotations())
return this.environment.createAnnotatedType(variable.withoutToplevelNullAnnotation(), originalType.getTypeAnnotations());
return variable;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceVariable.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceVariable.java
index e1064bc47e..e19f81d547 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceVariable.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceVariable.java
@@ -65,7 +65,7 @@ public class InferenceVariable extends TypeVariableBinding {
* Create or retrieve the inference variable representing the given typeParameter.
* Inference variables are interned to avoid duplication due to lambda copying.
*/
- public static InferenceVariable get(TypeBinding typeParameter, int rank, InvocationSite site, Scope scope, ReferenceBinding object) {
+ public static InferenceVariable get(TypeBinding typeParameter, int rank, InvocationSite site, Scope scope, ReferenceBinding object, boolean initial) {
Map<InferenceVarKey, InferenceVariable> uniqueInferenceVariables = scope.compilationUnitScope().uniqueInferenceVariables;
InferenceVariable var = null;
InferenceVarKey key = null;
@@ -75,7 +75,7 @@ public class InferenceVariable extends TypeVariableBinding {
}
if (var == null) {
int newVarId = uniqueInferenceVariables.size();
- var = new InferenceVariable(typeParameter, rank, newVarId, site, scope.environment(), object);
+ var = new InferenceVariable(typeParameter, rank, newVarId, site, scope.environment(), object, initial);
if (key != null)
uniqueInferenceVariables.put(key, var);
}
@@ -88,10 +88,13 @@ public class InferenceVariable extends TypeVariableBinding {
long nullHints; // one of TagBits.{AnnotationNonNull,AnnotationNullable} may steer inference into inferring nullness as well; set both bits to request avoidance.
private InferenceVariable prototype;
int varId; // this is used for constructing a source name like T#0.
+ public boolean isFromInitialSubstitution; // further ivars created during 18.5.2 (for capture bounds) set this to false
+ // to mark that they don't participate in any theta substitution
- private InferenceVariable(TypeBinding typeParameter, int parameterRank, int iVarId, InvocationSite site, LookupEnvironment environment, ReferenceBinding object) {
+ private InferenceVariable(TypeBinding typeParameter, int parameterRank, int iVarId, InvocationSite site, LookupEnvironment environment, ReferenceBinding object, boolean initial) {
this(typeParameter, parameterRank, site, makeName(typeParameter, iVarId), environment, object);
this.varId = iVarId;
+ this.isFromInitialSubstitution = initial;
}
private static char[] makeName(TypeBinding typeParameter, int iVarId) {
if (typeParameter.getClass() == TypeVariableBinding.class) {
@@ -126,6 +129,7 @@ public class InferenceVariable extends TypeVariableBinding {
clone.tagBits = this.tagBits;
clone.nullHints = this.nullHints;
clone.varId = this.varId;
+ clone.isFromInitialSubstitution = this.isFromInitialSubstitution;
clone.prototype = this;
return clone;
}

Back to the top