Fix for KT-11081: Reified type parameters are lost in anonymous object in inline function when using default value parameters
#KT-11081 Fixed
This commit is contained in:
@@ -285,7 +285,8 @@ public class MethodInliner {
|
||||
super.visitMethodInsn(opcode, changeOwnerForExternalPackage(owner, opcode), name, desc, itf);
|
||||
}
|
||||
}
|
||||
else if (ReifiedTypeInliner.isNeedClassReificationMarker(new MethodInsnNode(opcode, owner, name, desc, false))) {
|
||||
else if (ReifiedTypeInliner.isNeedClassReificationMarker(new MethodInsnNode(opcode, owner, name, desc, false)) &&
|
||||
!isDefaultCompilation()) {
|
||||
// we will put it if needed in anew processing
|
||||
}
|
||||
else {
|
||||
@@ -372,7 +373,7 @@ public class MethodInliner {
|
||||
) {
|
||||
if (isInliningLambda || InlineCodegenUtil.GENERATE_SMAP) {
|
||||
String varSuffix = inliningContext.isRoot() &&
|
||||
!((RootInliningContext) inliningContext).isDefaultCompilation &&
|
||||
!isDefaultCompilation() &&
|
||||
!InlineCodegenUtil.isFakeLocalVariableForInline(name) ?
|
||||
INLINE_FUN_VAR_SUFFIX : "";
|
||||
String varName = !varSuffix.isEmpty() && name.equals("this") ? name + "_" : name;
|
||||
@@ -440,7 +441,7 @@ public class MethodInliner {
|
||||
|
||||
if (frame != null) {
|
||||
if (ReifiedTypeInliner.isNeedClassReificationMarker(cur)) {
|
||||
awaitClassReification = true;
|
||||
awaitClassReification = !isDefaultCompilation();
|
||||
}
|
||||
else if (cur.getType() == AbstractInsnNode.METHOD_INSN) {
|
||||
if (InlineCodegenUtil.isFinallyStart(cur)) {
|
||||
@@ -804,4 +805,7 @@ public class MethodInliner {
|
||||
|
||||
}
|
||||
|
||||
private boolean isDefaultCompilation() {
|
||||
return inliningContext.isRoot() && ((RootInliningContext) inliningContext).isDefaultCompilation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import test.*
|
||||
|
||||
fun specifyOptionalArgument() = typeWithMessage<List<Int>>("Hello")
|
||||
|
||||
fun useDefault() = typeWithMessage<List<Int>>()
|
||||
|
||||
fun box(): String {
|
||||
val specifyOptionalArgument = specifyOptionalArgument()
|
||||
val useDefault = useDefault()
|
||||
|
||||
if (useDefault != specifyOptionalArgument) return "fail: $useDefault != $specifyOptionalArgument"
|
||||
|
||||
val type = typeWithMessage<List<Int>>("")
|
||||
if (type != " test.TypeRef<java.util.List<? extends java.lang.Integer>>") return "fail 2: $type"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package test
|
||||
|
||||
open class TypeRef<T> {
|
||||
val type = target()
|
||||
|
||||
private fun target(): String {
|
||||
val thisClass = this.javaClass
|
||||
val superClass = thisClass.genericSuperclass
|
||||
|
||||
return superClass.toString()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline fun <reified T> typeWithMessage(message: String = "Hello"): String {
|
||||
val type = object : TypeRef<T>() {}
|
||||
val target = type.type
|
||||
|
||||
return message + " " + target
|
||||
}
|
||||
+6
@@ -1456,6 +1456,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
||||
doTestMultiFileWithInlineCheck(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt11081.1.kt")
|
||||
public void testKt11081() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/reified/kt11081.1.kt");
|
||||
doTestMultiFileWithInlineCheck(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt6988.1.kt")
|
||||
public void testKt6988() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/reified/kt6988.1.kt");
|
||||
|
||||
+6
@@ -1456,6 +1456,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
||||
doBoxTestWithInlineCheck(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt11081.1.kt")
|
||||
public void testKt11081() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/reified/kt11081.1.kt");
|
||||
doBoxTestWithInlineCheck(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt6988.1.kt")
|
||||
public void testKt6988() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/reified/kt6988.1.kt");
|
||||
|
||||
Reference in New Issue
Block a user