Fix for KT-13374: CompilationException: Inline function call with anonymous object implementing an interface by delegation

#KT-13374 Fixed
This commit is contained in:
Michael Bogdanov
2016-08-15 14:46:58 +03:00
parent fca5834557
commit 7325baa06a
8 changed files with 57 additions and 7 deletions
@@ -1166,7 +1166,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
KotlinType expressionType = expression != null ? bindingContext.getType(expression) : null;
Type asmType =
expressionType != null ? typeMapper.mapType(expressionType) : typeMapper.mapType(getSuperClass(specifier));
result.addField((KtDelegatedSuperTypeEntry) specifier, asmType, "$delegate_" + n);
result.addField((KtDelegatedSuperTypeEntry) specifier, asmType, JvmAbi.DELEGATE_SUPER_FIELD_PREFIX + n);
}
n++;
}
@@ -24,16 +24,16 @@ class Test3() : Test2() {
fun box(): String {
try {
Test::class.java.getDeclaredField("\$delegate_0")
return "\$delegate_0 field generated for class Test but should not"
Test::class.java.getDeclaredField("\$\$delegate_0")
return "\$\$delegate_0 field generated for class Test but should not"
}
catch (e: NoSuchFieldException) {
// ok
}
try {
Test2::class.java.getDeclaredField("\$delegate_0")
return "\$delegate_0 field generated for class Test but should not"
Test2::class.java.getDeclaredField("\$\$delegate_0")
return "\$\$delegate_0 field generated for class Test but should not"
}
catch (e: NoSuchFieldException) {
// ok
@@ -0,0 +1,37 @@
// FILE: 1.kt
package test
interface IZ {
fun z()
}
interface IZZ : IZ {
fun zz()
}
inline fun implZZ(zImpl: IZ, crossinline zzImpl: () -> Unit): IZZ =
object : IZZ, IZ by zImpl {
override fun zz() = zzImpl()
}
// FILE: 2.kt
import test.*
var result = "fail";
object ZImpl : IZ {
override fun z() {
result = "O"
}
}
fun box(): String {
val zz = implZZ(ZImpl) { result += "K" }
zz.z()
zz.zz()
return result
}
@@ -1,5 +1,5 @@
interface Foo
class <!CONFLICTING_JVM_DECLARATIONS!>Bar(f: Foo)<!> : Foo by f {
<!CONFLICTING_JVM_DECLARATIONS!>val `$delegate_0`: Foo?<!> = null
<!CONFLICTING_JVM_DECLARATIONS!>val `$$delegate_0`: Foo?<!> = null
}
@@ -2,7 +2,7 @@ package
public final class Bar : Foo {
public constructor Bar(/*0*/ f: Foo)
public final val `$delegate_0`: Foo? = null
public final val `$$delegate_0`: Foo? = null
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
@@ -133,6 +133,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
doTest(fileName);
}
@TestMetadata("kt13374.kt")
public void testKt13374() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt13374.kt");
doTest(fileName);
}
@TestMetadata("kt6552.kt")
public void testKt6552() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
@@ -133,6 +133,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
doTest(fileName);
}
@TestMetadata("kt13374.kt")
public void testKt13374() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt13374.kt");
doTest(fileName);
}
@TestMetadata("kt6552.kt")
public void testKt6552() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
@@ -43,6 +43,7 @@ public final class JvmAbi {
public static final String DELEGATED_PROPERTY_NAME_SUFFIX = "$delegate";
public static final String DELEGATED_PROPERTIES_ARRAY_NAME = "$$delegatedProperties";
public static final String DELEGATE_SUPER_FIELD_PREFIX = "$$delegate_";
public static final String ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX = "$annotations";
public static final String INSTANCE_FIELD = "INSTANCE";