Handle @JvmOverloads on inner class constructors correctly
#KT-14678 Fixed
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.kotlin.codegen.JvmCodegenUtil.getDispatchReceiverParameterForConstructorCall
|
||||
import org.jetbrains.kotlin.codegen.binding.CodegenBinding
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
@@ -155,6 +156,15 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
|
||||
if (!isStatic) {
|
||||
val thisIndex = frameMap.enterTemp(AsmTypes.OBJECT_TYPE)
|
||||
v.load(thisIndex, methodOwner) // Load this on stack
|
||||
|
||||
if (functionDescriptor is ConstructorDescriptor) {
|
||||
val closure = state.bindingContext.get(CodegenBinding.CLOSURE, functionDescriptor.constructedClass)
|
||||
val captureThis = getDispatchReceiverParameterForConstructorCall(functionDescriptor, closure)
|
||||
if (captureThis != null) {
|
||||
val outerIndex = frameMap.enterTemp(AsmTypes.OBJECT_TYPE)
|
||||
v.load(outerIndex, typeMapper.mapType(captureThis))
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
val delegateOwner = delegateFunctionDescriptor.containingDeclaration
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Outer {
|
||||
inner class Inner @JvmOverloads constructor(val s1: String, val s2: String = "OK") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val outer = Outer()
|
||||
val c = (Outer.Inner::class.java.getConstructor(Outer::class.java, String::class.java).newInstance(outer, "shazam"))
|
||||
return c.s2
|
||||
}
|
||||
+6
@@ -8591,6 +8591,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerClass.kt")
|
||||
public void testInnerClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/innerClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("multipleDefaultParameters.kt")
|
||||
public void testMultipleDefaultParameters() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/multipleDefaultParameters.kt");
|
||||
|
||||
@@ -8591,6 +8591,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerClass.kt")
|
||||
public void testInnerClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/innerClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("multipleDefaultParameters.kt")
|
||||
public void testMultipleDefaultParameters() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/multipleDefaultParameters.kt");
|
||||
|
||||
+12
@@ -10373,6 +10373,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||
}
|
||||
|
||||
@TestMetadata("innerClass.kt")
|
||||
public void testInnerClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/innerClass.kt");
|
||||
try {
|
||||
doTest(fileName);
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
return;
|
||||
}
|
||||
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||
}
|
||||
|
||||
@TestMetadata("multipleDefaultParameters.kt")
|
||||
public void testMultipleDefaultParameters() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/multipleDefaultParameters.kt");
|
||||
|
||||
Reference in New Issue
Block a user