Skip to content

Commit

Permalink
Apply the boxing conversion post instanceof where required (#2105)
Browse files Browse the repository at this point in the history
* Fixes #2104
  • Loading branch information
srikanth-sankaran committed Mar 6, 2024
1 parent d714fcd commit 10d3cec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,14 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean
codeStream.iconst_0();

continueLabel.place();
} else if (!valueRequired) {
codeStream.pop();
}

if (valueRequired) {
codeStream.generateImplicitConversion(this.implicitConversion);
} else if (this.pattern == null) {
codeStream.pop(); // in the pattern case, if (!valueRequired), we have nothing on the stack to pop
}

codeStream.recordPositionsFrom(codeStream.position, this.sourceEnd);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4812,4 +4812,32 @@ public static void main(String [] args) {
"for\n"
+ "!for");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2104
// [Patterns] Missing boxing conversion after instanceof leads to verify error
public void testBoxing() {
runConformTest(
new String[] {
"X.java",
"""
public class X {
public static void foo(Boolean b) {
System.out.println(b);
}
public static void main(String [] args) {
Object o = new Object();
foo(o instanceof String);
foo("Hello" instanceof String);
foo(o instanceof String s);
foo("Hello" instanceof String s);
}
}
""",
},
"false\n"
+ "true\n"
+ "false\n"
+ "true");
}
}

0 comments on commit 10d3cec

Please sign in to comment.