Skip to content

Commit

Permalink
Allow using generics with pattern matching instanceof (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
coehlrich authored Sep 11, 2023
1 parent 63fcba8 commit 5e8dd19
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,15 @@ private static boolean checkBranch(Exprent exprent, IfStatement statement, State
return false;
}
}

VarType storeType = left.getInferredExprType(null);

// Add the exprent to the instanceof exprent and remove it from the inside of the if statement
iof.getLstOperands().add(2, left);
head.getExprents().remove(0);
if (storeType.isGeneric()) {
iof.getLstOperands().set(1, new ConstExprent(storeType, null, iof.getLstOperands().get(1).bytecode));
}

statement.setPatternMatched(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class TestSwitchPatternMatchingInstanceof4 {
public void test(Object o) {
Objects.requireNonNull(o);// 5
switch (o) {
case String s when o instanceof Class clzz && clzz.getSigners()[0] instanceof Class c2:// 6
case String s when o instanceof Class<?> clzz && clzz.getSigners()[0] instanceof Class<?> c2:// 6
System.out.println("" + clzz + c2);
break;
default:
Expand Down

0 comments on commit 5e8dd19

Please sign in to comment.