Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorssankaran2014-03-09 13:11:22 +0000
committerssankaran2014-03-09 13:11:22 +0000
commitd40d65cc310f8b80e4964046fc88b861b3de2b63 (patch)
tree055ae904ba421ecf8802ef448423da3cf24ee75b
parent8d4ab5644565c055b67fa7745388cbe96026e76a (diff)
downloadeclipse.jdt.core-d40d65cc310f8b80e4964046fc88b861b3de2b63.tar.gz
eclipse.jdt.core-d40d65cc310f8b80e4964046fc88b861b3de2b63.tar.xz
eclipse.jdt.core-d40d65cc310f8b80e4964046fc88b861b3de2b63.zip
Amended fix for Bug 429934 - [1.8][search] for references to type of
lambda with 'this' parameter throws AIIOBE
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests18.java27
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java15
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/HandleFactory.java3
3 files changed, 38 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests18.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests18.java
index bcba581008..9c91c293a8 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests18.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests18.java
@@ -2340,4 +2340,31 @@ public void test429948() throws JavaModelException {
elements, true
);
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429934, [1.8][search] for references to type of lambda with 'this' parameter throws AIIOBE
+public void test429934() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Resolve/src/X.java",
+ "interface Function<T, R> {\n" +
+ " R apply(T t);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " Function<String, String> f1= (String s, Function this) -> s;\n" +
+ " Function<String, String> f2= (Function this, String s) -> s;\n" +
+ " } \n" +
+ "}\n"
+ );
+
+ String str = this.workingCopies[0].getSource();
+ String selection = "s";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "s [in main(String[]) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements, true
+ );
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
index 33e1f69520..acfed80b45 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
@@ -216,8 +216,6 @@ public class LambdaExpression extends FunctionalExpression implements ReferenceC
*/
public TypeBinding resolveType(BlockScope blockScope) {
- boolean illFormed = false;
-
if (this.resolvedType != null)
return this.resolvedType;
@@ -257,16 +255,21 @@ public class LambdaExpression extends FunctionalExpression implements ReferenceC
blockScope.enclosingSourceType());
this.binding.typeVariables = Binding.NO_TYPE_VARIABLES;
+ boolean buggyArguments = false;
if (haveDescriptor) {
int descriptorParameterCount = this.descriptor.parameters.length;
int lambdaArgumentCount = this.arguments != null ? this.arguments.length : 0;
if (descriptorParameterCount != lambdaArgumentCount) {
this.scope.problemReporter().lambdaSignatureMismatched(this);
- return this.resolvedType = null; // FUBAR, bail out ...
+ if (argumentsTypeElided || this.original != this) // no interest in continuing to error check copy.
+ return this.resolvedType = null; // FUBAR, bail out ...
+ else {
+ this.resolvedType = null; // continue to type check.
+ buggyArguments = true;
+ }
}
}
- boolean buggyArguments = false;
TypeBinding[] newParameters = new TypeBinding[length];
AnnotationBinding [][] parameterAnnotations = null;
@@ -326,7 +329,7 @@ public class LambdaExpression extends FunctionalExpression implements ReferenceC
if (haveDescriptor && expectedParameterType != null && parameterType.isValidBinding() && TypeBinding.notEquals(parameterType, expectedParameterType)) {
if (!(expectedParameterType instanceof InferenceVariable)) {
this.scope.problemReporter().lambdaParameterTypeMismatched(argument, argument.type, expectedParameterType);
- illFormed = true; // continue to type check.
+ this.resolvedType = null; // continue to type check.
}
}
@@ -414,7 +417,7 @@ public class LambdaExpression extends FunctionalExpression implements ReferenceC
if ((this.binding.tagBits & TagBits.HasMissingType) != 0) {
this.scope.problemReporter().missingTypeInLambda(this, this.binding);
}
- return illFormed ? this.resolvedType = null : this.resolvedType;
+ return this.resolvedType;
}
private ReferenceBinding findGroundTargetType(BlockScope blockScope, ReferenceBinding targetType, boolean argumentTypesElided) {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/HandleFactory.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/HandleFactory.java
index 48f837e7ca..aad80e365e 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/HandleFactory.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/HandleFactory.java
@@ -211,13 +211,14 @@ public class HandleFactory {
break;
case Scope.METHOD_SCOPE :
if (scope.isLambdaScope()) {
+ parentElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
LambdaExpression expression = (LambdaExpression) scope.originalReferenceContext();
if (expression.resolvedType != null && expression.resolvedType.isValidBinding()) { // chain in lambda element only if resolved properly.
- parentElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
newElement = new org.eclipse.jdt.internal.core.LambdaExpression((JavaElement) parentElement, expression).getMethod();
knownScopes.put(scope, newElement);
return newElement;
}
+ return parentElement;
}
IType parentType = (IType) createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
MethodScope methodScope = (MethodScope) scope;

Back to the top