Skip to content

Commit

Permalink
Fix for problems reported by Jay introduced by the fix for
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-sankaran committed Mar 5, 2024
1 parent 2325a3b commit ed7528c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean
}
if (this.rightInitStateIndex != -1) {
codeStream.addDefinitelyAssignedVariables(currentScope, this.rightInitStateIndex);
codeStream.removeNotDefinitelyAssignedVariables(currentScope, this.rightInitStateIndex);
}
if (rightIsConst) {
this.right.generateCode(currentScope, codeStream, false);
Expand Down Expand Up @@ -230,8 +231,8 @@ public void generateOptimizedBoolean(BlockScope currentScope, CodeStream codeStr
break generateOperands; // no need to generate right operand
}
if (this.rightInitStateIndex != -1) {
codeStream
.addDefinitelyAssignedVariables(currentScope, this.rightInitStateIndex);
codeStream.addDefinitelyAssignedVariables(currentScope, this.rightInitStateIndex);
codeStream.removeNotDefinitelyAssignedVariables(currentScope, this.rightInitStateIndex);
}
this.right.generateOptimizedBoolean(currentScope, codeStream, trueLabel, null,
valueRequired && !rightIsConst);
Expand All @@ -255,8 +256,8 @@ public void generateOptimizedBoolean(BlockScope currentScope, CodeStream codeStr
break generateOperands; // no need to generate right operand
}
if (this.rightInitStateIndex != -1) {
codeStream
.addDefinitelyAssignedVariables(currentScope, this.rightInitStateIndex);
codeStream.addDefinitelyAssignedVariables(currentScope, this.rightInitStateIndex);
codeStream.removeNotDefinitelyAssignedVariables(currentScope, this.rightInitStateIndex);
}
this.right.generateOptimizedBoolean(currentScope, codeStream, null, falseLabel, valueRequired && !rightIsConst);
if (valueRequired && rightIsConst && !rightIsTrue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4548,4 +4548,33 @@ public static void main(String [] args) {
options);

}
// Test for regression caused by fix for https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1889
public void testIssue1889() {
runConformTest(
new String[] {
"X.java",
"""
public class X {
static public Object a0 = "a";
public static void main(String argv[]) {
String res = "";
Object ax = a0;
if ( (! (ax instanceof String a)) && (ax instanceof String a) ) {
res += "t" + a; // after then
} else {
res += "e" + ""; // after else
}
if (!res.equals("e")) {
System.out.println("Got: " + res + ", expected: e");
} else {
System.out.println("OK!");
}
}
}
""",
},
"OK!");
}
}

0 comments on commit ed7528c

Please sign in to comment.