Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2015-06-12 18:49:53 +0000
committerJay Arthanareeswaran2015-07-30 16:30:43 +0000
commitdba3d88819f31e52c7b1709da4ad2221836bbba2 (patch)
treecf4e74f98c05d20003678c5536a7ebccae82625d
parent1e67b69a4e26c9f884bed13126abbad62ee85725 (diff)
downloadeclipse.jdt.core-dba3d88819f31e52c7b1709da4ad2221836bbba2.tar.gz
eclipse.jdt.core-dba3d88819f31e52c7b1709da4ad2221836bbba2.tar.xz
eclipse.jdt.core-dba3d88819f31e52c7b1709da4ad2221836bbba2.zip
Bug 463728: [1.8][compiler][inference] Ternary operator in lambda
derives wrong type Change-Id: I437fe9955a5bec0be699a66f0fc6a68b4a94f1fd
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java36
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java15
2 files changed, 43 insertions, 8 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 d55606d9b3..99e352b19d 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
@@ -5228,4 +5228,40 @@ public void testBug445231() {
"not anon\n" +
"Ok", null);
}
+public void testBug463728() {
+ runConformTest(
+ new String[] {
+ "Main.java",
+ "import java.util.function.Function;\n" +
+ "\n" +
+ "\n" +
+ "class Color {\n" +
+ " \n" +
+ "}\n" +
+ "\n" +
+ "class TypeMapper<R> {\n" +
+ "\n" +
+ " public TypeMapper() {\n" +
+ " }\n" +
+ " public R orElse(R result) {\n" +
+ " return result;\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "public class Main {\n" +
+ " Color A;\n" +
+ " Color B;\n" +
+ "\n" +
+ " public static <T, R> TypeMapper<R> mapType(Function<T, R> mapper) {\n" +
+ " return new TypeMapper<R>();\n" +
+ " }\n" +
+ "\n" +
+ " public Color getForeground(Object element) {\n" +
+ " return mapType(library -> {\n" +
+ " return (element != null ? A : B);\n" +
+ " }).orElse(null);\n" +
+ " }\n" +
+ "}\n"
+ });
+}
}
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 8fc1d41a59..877114a78c 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2014 IBM Corporation and others.
+ * Copyright (c) 2012, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -36,6 +36,7 @@
* Bug 452788 - [1.8][compiler] Type not correctly inferred in lambda expression
* Bug 453483 - [compiler][null][loop] Improve null analysis for loops
* Bug 455723 - Nonnull argument not correctly inferred in loop
+ * Bug 463728 - [1.8][compiler][inference] Ternary operator in lambda derives wrong type
* Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
* Bug 405104 - [1.8][compiler][codegen] Implement support for serializeable lambdas
*******************************************************************************/
@@ -981,13 +982,11 @@ public class LambdaExpression extends FunctionalExpression implements IPolyExpre
this.returnsValue = true;
this.voidCompatible = false;
this.valueCompatible = !this.returnsVoid;
- if (resultType != null) {
- Expression [] returnExpressions = this.resultExpressions;
- int resultsLength = returnExpressions.length;
- System.arraycopy(returnExpressions, 0, returnExpressions = new Expression[resultsLength + 1], 0, resultsLength);
- returnExpressions[resultsLength] = expression;
- this.resultExpressions = returnExpressions;
- }
+ Expression [] returnExpressions = this.resultExpressions;
+ int resultsLength = returnExpressions.length;
+ System.arraycopy(returnExpressions, 0, returnExpressions = new Expression[resultsLength + 1], 0, resultsLength);
+ returnExpressions[resultsLength] = expression;
+ this.resultExpressions = returnExpressions;
} else {
this.returnsVoid = true;
this.valueCompatible = false;

Back to the top