From e0adfd453f1dd67f690598e62ec1069be096862f Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Sun, 3 Apr 2016 16:24:48 +0300 Subject: [PATCH] Fix for KT-11677: Generic type signatures for local classes in inlined lambdas are not written properly #KT-11677 Fixed --- .../kotlin/codegen/inline/MethodInliner.java | 4 +-- .../codegen/boxInline/reified/kt11677.kt | 33 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 6 ++++ ...otlinAgainstInlineKotlinTestGenerated.java | 6 ++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/boxInline/reified/kt11677.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 0ced7f7faa3..83031a89b80 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java @@ -292,8 +292,8 @@ public class MethodInliner { super.visitMethodInsn(opcode, changeOwnerForExternalPackage(owner, opcode), name, desc, itf); } } - else if (ReifiedTypeInliner.isNeedClassReificationMarker(new MethodInsnNode(opcode, owner, name, desc, false))) { - // we will put it if needed in anew processing + else if (!inliningContext.isInliningLambda && ReifiedTypeInliner.isNeedClassReificationMarker(new MethodInsnNode(opcode, owner, name, desc, false))) { + //we shouldn't process here content of inlining lambda it should be reified at external level } else { super.visitMethodInsn(opcode, changeOwnerForExternalPackage(owner, opcode), name, desc, itf); diff --git a/compiler/testData/codegen/boxInline/reified/kt11677.kt b/compiler/testData/codegen/boxInline/reified/kt11677.kt new file mode 100644 index 00000000000..26a0ee7fcdc --- /dev/null +++ b/compiler/testData/codegen/boxInline/reified/kt11677.kt @@ -0,0 +1,33 @@ +// FILE: 1.kt +// FULL_JDK +// WITH_REFLECT + +package test + +import java.lang.reflect.ParameterizedType +import java.lang.reflect.Type + +open class TypeLiteral { + val type: Type + get() = (javaClass.genericSuperclass as ParameterizedType).getActualTypeArguments()[0] +} + +// normal inline function works fine +inline fun typeLiteral(): TypeLiteral = object : TypeLiteral() {} + +// nested lambda loses reification of T +inline fun brokenTypeLiteral(): TypeLiteral = "".run { typeLiteral() } + +// FILE: 2.kt + +import test.* + +fun box(): String { + val type1 = typeLiteral>().type.toString() + if (type1 != "java.util.List") return "fail 1: $type1" + + val type2 = brokenTypeLiteral>().type.toString() + if (type2 != "java.util.List") return "fail 2: $type2" + + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 3000b7cd2d1..1438eb763b0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -1525,6 +1525,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("kt11677.kt") + public void testKt11677() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/reified/kt11677.kt"); + doTest(fileName); + } + @TestMetadata("kt6988.kt") public void testKt6988() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/reified/kt6988.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 4d36e097c56..37085dd83e5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -1525,6 +1525,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("kt11677.kt") + public void testKt11677() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/reified/kt11677.kt"); + doTest(fileName); + } + @TestMetadata("kt6988.kt") public void testKt6988() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/reified/kt6988.kt");