diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/proxy/CommonProxy.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/proxy/CommonProxy.kt index 77295beba80..f92ced1b818 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/proxy/CommonProxy.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/proxy/CommonProxy.kt @@ -80,7 +80,7 @@ internal class CommonProxy private constructor(override val state: Common, overr method.name == "toString" && method.parameterTypes.isEmpty() -> commonProxy.toString() else -> { val irFunction = commonProxy.state.getIrFunction(method) - ?: throw AssertionError("Cannot find method $method in ${commonProxy.state}") + ?: return@newProxyInstance commonProxy.fallbackIfMethodNotFound(method) val valueArguments = mutableListOf() valueArguments += Variable(irFunction.getDispatchReceiver()!!, commonProxy.state) valueArguments += irFunction.valueParameters @@ -90,5 +90,15 @@ internal class CommonProxy private constructor(override val state: Common, overr } } } + + private fun CommonProxy.fallbackIfMethodNotFound(method: java.lang.reflect.Method): Any { + return when { + method.name == "toArray" && method.parameterTypes.isEmpty() -> { + val wrapper = this.state.superWrapperClass + if (wrapper == null) arrayOf() else (wrapper as Collection<*>).toTypedArray() + } + else -> throw AssertionError("Cannot find method $method in ${this.state}") + } + } } } \ No newline at end of file diff --git a/compiler/testData/ir/interpreter/proxy/superWrapper.kt b/compiler/testData/ir/interpreter/proxy/superWrapper.kt index 24444143c35..8d6156b3b44 100644 --- a/compiler/testData/ir/interpreter/proxy/superWrapper.kt +++ b/compiler/testData/ir/interpreter/proxy/superWrapper.kt @@ -24,6 +24,7 @@ fun test(list: MyArrayList): String { val otherList = arrayListOf(4, 5, 6) list.addAll(otherList) + list.addAll(emptyList()) return "Counter " + list.addCounter + "; size " + list.size }