Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesper Steen Møller2021-03-29 20:45:33 +0000
committerJesper Moller2021-04-29 06:45:31 +0000
commit01b98e66066476e5b62cd990931342d1cc4619d3 (patch)
treea402c94893bb1a18c3f30e73d2bba816789876fd
parent9f4685b2c86042fb6e5d6c73005604fe6443e0da (diff)
downloadeclipse.jdt.core-01b98e66066476e5b62cd990931342d1cc4619d3.tar.gz
eclipse.jdt.core-01b98e66066476e5b62cd990931342d1cc4619d3.tar.xz
eclipse.jdt.core-01b98e66066476e5b62cd990931342d1cc4619d3.zip
Bug 572380 - [16][pattern instanceof] pattern variable not found in &&I20210429-0600
Signed-off-by: Jesper Steen Møller <jesper@selskabet.org> Also-By: Jay Arthanareeswaran <jarthana@in.ibm.com> Change-Id: I98cf907640520194d647817a58feec9b520c853e Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/179964
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java51
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java4
2 files changed, 55 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java
index c70b5685f0..9ff4f68838 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java
@@ -3656,4 +3656,55 @@ public class PatternMatching16Test extends AbstractRegressionTest {
true,
compilerOptions);
}
+ public void testBug572380_1() {
+ Map<String, String> options = getCompilerOptions(false);
+ runConformTest(
+ new String[] {
+ "X1.java",
+ "\n"
+ + "public class X1 {\n"
+ + " boolean b1, b2, b3;\n"
+ + "\n"
+ + " static boolean bubbleOut(Object obj) {\n"
+ + " return obj instanceof X1 that && that.b1 && that.b2 && that.b3;\n"
+ + " }\n"
+ + "\n"
+ + " static boolean propagateTrueIn(Object obj) {\n"
+ + " return obj instanceof X1 that && (that.b1 && that.b2 && that.b3);\n"
+ + " }\n"
+ + "\n"
+ + " public static void main(String[] obj) {\n"
+ + " var ip = new X1();\n"
+ + " ip.b1 = ip.b2 = ip.b3 = true;\n"
+ + " System.out.println(bubbleOut(ip) && propagateTrueIn(ip));\n"
+ + " }\n"
+ + "\n"
+ + "}\n",
+ },
+ "true",
+ options);
+ }
+ public void testBug572380_2() {
+ Map<String, String> options = getCompilerOptions(false);
+ runConformTest(
+ new String[] {
+ "X1.java",
+ "\n"
+ + "public class X1 {\n"
+ + " boolean b1, b2, b3;\n"
+ + " static boolean testErrorOr(Object obj) {\n"
+ + " return (!(obj instanceof X1 that)) || that.b1 && that.b2;\n"
+ + " }\n"
+ + " \n"
+ + " public static void main(String[] obj) {\n"
+ + " var ip = new X1();\n"
+ + " ip.b1 = ip.b2 = ip.b3 = true;\n"
+ + " System.out.println(testErrorOr(ip));\n"
+ + " }\n"
+ + "\n"
+ + "}\n",
+ },
+ "true",
+ options);
+ }
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java
index 478d32d408..9acba9562a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java
@@ -274,6 +274,10 @@ public class AND_AND_Expression extends BinaryExpression {
}
@Override
public void collectPatternVariablesToScope(LocalVariableBinding[] variables, BlockScope scope) {
+ this.addPatternVariablesWhenTrue(variables);
+ // If upper level already supplied positive new vars for us, also make those available to the left expr
+ this.left.addPatternVariablesWhenTrue(this.patternVarsWhenTrue);
+
this.left.collectPatternVariablesToScope(this.patternVarsWhenTrue, scope);
variables = this.left.getPatternVariablesWhenTrue();

Back to the top