diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt index ac120eb02da..bca3fa1f995 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt @@ -143,7 +143,10 @@ class VariableTypeAndInitializerResolver( variableDescriptor, delegateExpression, type, trace, scopeForInitializer, dataFlowInfo ) - getterReturnType?.let { approximateType(it, local) } ?: ErrorUtils.createErrorType("Type from delegate") + val delegatedType = getterReturnType?.let { approximateType(it, local) } + ?: ErrorUtils.createErrorType("Type from delegate") + + transformAnonymousTypeIfNeeded(variableDescriptor, property, delegatedType, trace, anonymousTypeTransformers) } private fun resolveInitializerType( diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/KaptAnonymousTypeTransformer.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/KaptAnonymousTypeTransformer.kt index 2803e89257e..5dc87d88fee 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/KaptAnonymousTypeTransformer.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/KaptAnonymousTypeTransformer.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility import org.jetbrains.kotlin.resolve.DeclarationSignatureAnonymousTypeTransformer +import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils.* import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeProjectionImpl @@ -37,9 +38,9 @@ class KaptAnonymousTypeTransformer : DeclarationSignatureAnonymousTypeTransforme } val actualType = when { - isAnonymousObject(declaration) -> { + isAnonymousObject(declaration) || DescriptorUtils.isLocal(declaration) -> { if (type.constructor.supertypes.size == 1) { - type.constructor.supertypes.iterator().next() + convertPossiblyAnonymousType(type.constructor.supertypes.iterator().next()) } else { /* Frontend reports an error on public properties in this case, diff --git a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java index 86ca9cd75b0..ea9aab5d8d1 100644 --- a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java +++ b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java @@ -264,6 +264,11 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi runTest("plugins/kapt3/kapt3-compiler/testData/converter/kt27126.kt"); } + @TestMetadata("lazyProperty.kt") + public void testLazyProperty() throws Exception { + runTest("plugins/kapt3/kapt3-compiler/testData/converter/lazyProperty.kt"); + } + @TestMetadata("leadingDollars.kt") public void testLeadingDollars() throws Exception { runTest("plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars.kt"); diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/lazyProperty.kt b/plugins/kapt3/kapt3-compiler/testData/converter/lazyProperty.kt new file mode 100644 index 00000000000..4c7112ce3c8 --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/lazyProperty.kt @@ -0,0 +1,28 @@ +// WITH_RUNTIME + +interface Intf +interface GenericIntf + +class Foo { + private val foo by lazy { + object : Runnable { + override fun run() {} + } + } + + private val bar by lazy { + object : Runnable, Intf { + override fun run() {} + } + } + + private val baz by lazy { + abstract class LocalIntf + object : LocalIntf() {} + } + + private val generic1 by lazy { + abstract class LocalIntf : GenericIntf + object : LocalIntf() {} + } +} diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/lazyProperty.txt b/plugins/kapt3/kapt3-compiler/testData/converter/lazyProperty.txt new file mode 100644 index 00000000000..c94dce768d6 --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/lazyProperty.txt @@ -0,0 +1,47 @@ +import java.lang.System; + +@kotlin.Metadata() +public final class Foo { + private final kotlin.Lazy foo$delegate = null; + private final kotlin.Lazy bar$delegate = null; + private final kotlin.Lazy baz$delegate = null; + private final kotlin.Lazy generic1$delegate = null; + + private final java.lang.Runnable getFoo() { + return null; + } + + private final java.lang.Object getBar() { + return null; + } + + private final java.lang.Object getBaz() { + return null; + } + + private final GenericIntf getGeneric1() { + return null; + } + + public Foo() { + super(); + } +} + +//////////////////// + + +import java.lang.System; + +@kotlin.Metadata() +public abstract interface GenericIntf { +} + +//////////////////// + + +import java.lang.System; + +@kotlin.Metadata() +public abstract interface Intf { +}