From 405c21a17e2c72490075d8b1916d606a220e8566 Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Thu, 18 Feb 2016 15:23:39 +0300 Subject: [PATCH] Fix for KT-11081: Reified type parameters are lost in anonymous object in inline function when using default value parameters #KT-11081 Fixed --- .../kotlin/codegen/inline/MethodInliner.java | 10 ++++++--- .../codegen/boxInline/reified/kt11081.1.kt | 17 +++++++++++++++ .../codegen/boxInline/reified/kt11081.2.kt | 21 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 6 ++++++ ...otlinAgainstInlineKotlinTestGenerated.java | 6 ++++++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/codegen/boxInline/reified/kt11081.1.kt create mode 100644 compiler/testData/codegen/boxInline/reified/kt11081.2.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java index f6d6b16b4cb..ff865c2623b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java @@ -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; + } } diff --git a/compiler/testData/codegen/boxInline/reified/kt11081.1.kt b/compiler/testData/codegen/boxInline/reified/kt11081.1.kt new file mode 100644 index 00000000000..2d9636bfbcc --- /dev/null +++ b/compiler/testData/codegen/boxInline/reified/kt11081.1.kt @@ -0,0 +1,17 @@ +import test.* + +fun specifyOptionalArgument() = typeWithMessage>("Hello") + +fun useDefault() = typeWithMessage>() + +fun box(): String { + val specifyOptionalArgument = specifyOptionalArgument() + val useDefault = useDefault() + + if (useDefault != specifyOptionalArgument) return "fail: $useDefault != $specifyOptionalArgument" + + val type = typeWithMessage>("") + if (type != " test.TypeRef>") return "fail 2: $type" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/reified/kt11081.2.kt b/compiler/testData/codegen/boxInline/reified/kt11081.2.kt new file mode 100644 index 00000000000..2e228905736 --- /dev/null +++ b/compiler/testData/codegen/boxInline/reified/kt11081.2.kt @@ -0,0 +1,21 @@ +package test + +open class TypeRef { + val type = target() + + private fun target(): String { + val thisClass = this.javaClass + val superClass = thisClass.genericSuperclass + + return superClass.toString() + } +} + + + +inline fun typeWithMessage(message: String = "Hello"): String { + val type = object : TypeRef() {} + val target = type.type + + return message + " " + target +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java index 04959652f96..22202dfedf5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java index 28c14eb5d3c..9720f31fccd 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -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");