diff --git a/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt b/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt index 6ccf06c..723c377 100644 --- a/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt +++ b/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt @@ -101,12 +101,20 @@ fun MutableMethod.removeInstruction(index: Int) = this.implementation!!.removeIn fun MutableMethod.label(index: Int) = this.implementation!!.newLabelForIndex(index) /** - * Get the instruction at the given index in the method's implementation. + * Get an instruction at the given index in the method's implementation. * @param index The index to get the instruction at. * @return The instruction. */ fun MutableMethod.instruction(index: Int): BuilderInstruction = this.implementation!!.instructions[index] +/** + * Get an instruction at the given index in the method's implementation. + * @param index The index to get the instruction at. + * @param T The type of instruction to return. + * @return The instruction. + */ +fun MutableMethod.instruction(index: Int): T = instruction(index) as T + /** * Add smali instructions to the method. * @param index The index to insert the instructions at. diff --git a/src/test/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompilerTest.kt b/src/test/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompilerTest.kt index 0abe1d7..9d1bbd4 100644 --- a/src/test/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompilerTest.kt +++ b/src/test/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompilerTest.kt @@ -44,7 +44,7 @@ internal class InlineSmaliCompilerTest { """ ) - val insn = method.instruction(insnIndex) as BuilderInstruction21t + val insn = method.instruction(insnIndex) assertEquals(targetIndex, insn.target.location.index) } @@ -73,7 +73,7 @@ internal class InlineSmaliCompilerTest { ) ) - val insn = method.instruction(insnIndex) as BuilderInstruction21t + val insn = method.instruction(insnIndex) assertTrue(insn.target.isPlaced, "Label was not placed") assertEquals(labelIndex, insn.target.location.index) }