Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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