Fix checkcast on Emulated interface dispatch
Change-Id: I96fa630f54169adbe884bc0f18235c2d7660ad96
diff --git a/src/main/java/com/android/tools/r8/ir/synthetic/EmulateDispatchSyntheticCfCodeProvider.java b/src/main/java/com/android/tools/r8/ir/synthetic/EmulateDispatchSyntheticCfCodeProvider.java
index d4d8f78..9c34153 100644
--- a/src/main/java/com/android/tools/r8/ir/synthetic/EmulateDispatchSyntheticCfCodeProvider.java
+++ b/src/main/java/com/android/tools/r8/ir/synthetic/EmulateDispatchSyntheticCfCodeProvider.java
@@ -99,7 +99,7 @@
// Call basic block.
instructions.add(new CfLoad(ValueType.fromDexType(receiverType), 0));
- forwardCall(instructions, dispatch.getValue());
+ forwardCall(instructions, dispatch.getValue(), dispatch.getKey());
addReturn(instructions);
}
@@ -107,22 +107,23 @@
instructions.add(labels[nextLabel]);
instructions.add(frame.clone());
instructions.add(new CfLoad(ValueType.fromDexType(receiverType), 0));
- forwardCall(instructions, forwardingMethod);
+ forwardCall(instructions, forwardingMethod, null);
addReturn(instructions);
return standardCfCodeFromInstructions(instructions);
}
- private void forwardCall(List<CfInstruction> instructions, DexMethod method) {
+ private void forwardCall(
+ List<CfInstruction> instructions, DexMethod method, DexType checkCastType) {
+ if (checkCastType != null) {
+ instructions.add(new CfCheckCast(checkCastType));
+ }
+ loadExtraParameters(instructions);
if (dispatchType == ALL_STATIC
|| appView.getSyntheticItems().isSynthetic(method.getHolderType())) {
- instructions.add(new CfCheckCast(method.getParameter(0)));
- loadExtraParameters(instructions);
instructions.add(new CfInvoke(Opcodes.INVOKESTATIC, method, false));
return;
}
assert dispatchType == AUTO_CLOSEABLE;
- instructions.add(new CfCheckCast(method.holder));
- loadExtraParameters(instructions);
// The type method.getHolderType() may not resolve if compiled without android library, for
// example, with the jdk as android.jar.
if (method