diff options
author | Jay Arthanareeswaran | 2020-12-09 06:59:09 +0000 |
---|---|---|
committer | Jayaprakash Arthanareeswaran | 2021-01-11 07:29:48 +0000 |
commit | 1f0d2c5ae30896854ae9635225c8cb756863e24f (patch) | |
tree | cbbf27468ec5dddbf3106423a3bdefe357a44e39 | |
parent | 92d33b49059ac5880a87d8b64016293328c56a92 (diff) | |
download | eclipse.jdt.core-1f0d2c5ae30896854ae9635225c8cb756863e24f.tar.gz eclipse.jdt.core-1f0d2c5ae30896854ae9635225c8cb756863e24f.tar.xz eclipse.jdt.core-1f0d2c5ae30896854ae9635225c8cb756863e24f.zip |
Bug 569498 - field "cannot be resolved to a variable" in ternaryI20210122-0800I20210122-0630I20210122-0420R4_18_maintenance
expression as method argument with String expression type
Change-Id: Ic1a45581a7fa75bbe2f94cc630f83425d483be1a
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>(cherry picked from commit 969dd97a97297dd985f4c924014f0537a709fc52)
2 files changed, 23 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConstantTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConstantTest.java index 3d23a15138..0b9d164003 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConstantTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConstantTest.java @@ -45,7 +45,7 @@ public ConstantTest(String name) { // All specified tests which does not belong to the class are skipped... static { // TESTS_PREFIX = "testBug95521"; -// TESTS_NAMES = new String[] { "testBug83127a" }; +// TESTS_NAMES = new String[] { "testBug566332_01" }; // TESTS_NUMBERS = new int[] { 21 }; // TESTS_RANGE = new int[] { 23, -1 }; } @@ -1604,6 +1604,25 @@ public void testBug566332_04() { "case expressions must be constant expressions\n" + "----------\n"); } +public void testBug569498() { + if (this.complianceLevel < ClassFileConstants.JDK11) { + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " final String s1 = \"\";\n" + + " public void m(Object s) {\n" + + " final boolean b = false;\n" + + " final String s2 = \"\";\n" + + " m(b? s1 : s2);\n" + + " }\n" + + " public static void main(String[] args) {}\n" + + "}", + }, + ""); +} public static Class testClass() { return ConstantTest.class; } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java index 0dcd9d3fef..8d49d80066 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java @@ -521,6 +521,9 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, } if (isPolyExpression()) { if (this.expectedType == null || !this.expectedType.isProperType(true)) { + // We will be back here in case of a PolyTypeBinding. So, to enable + // further processing, set it back to default. + this.constant = Constant.NotAConstant; return new PolyTypeBinding(this); } return this.resolvedType = computeConversions(scope, this.expectedType) ? this.expectedType : null; |