diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt index d8b7b486a4f..4b74b726407 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt @@ -574,7 +574,7 @@ class DelegatedPropertyResolver( val resolvedDelegateType = extractResolvedDelegateType(delegateExpression, trace) - return AnonymousTypeSubstitutor.safeSubstitute(resolvedDelegateType.unwrap()) + return TypeSubstitutor.create(AnonymousTypeSubstitutor).safeSubstitute(resolvedDelegateType, Variance.INVARIANT).unwrap() } private fun extractResolvedDelegateType(delegateExpression: KtExpression, trace: BindingTrace): KotlinType { @@ -703,11 +703,11 @@ class DelegatedPropertyResolver( } } -private object AnonymousTypeSubstitutor : NewTypeSubstitutor { - override fun substituteNotNullTypeWithConstructor(constructor: TypeConstructor): UnwrappedType? { - val declarationDescriptor = constructor.declarationDescriptor +private object AnonymousTypeSubstitutor : TypeConstructorSubstitution() { + override fun get(key: TypeConstructor): TypeProjection? { + val declarationDescriptor = key.declarationDescriptor if (declarationDescriptor is ClassifierDescriptor && DescriptorUtils.isAnonymousObject(declarationDescriptor)) { - return constructor.supertypes.firstOrNull()?.unwrap() + return key.supertypes.firstOrNull()?.let(::TypeProjectionImpl) } return null diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.kt index 3a3b62a9352..5cc2c1fec01 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.kt @@ -14,6 +14,12 @@ private val withTwoSupertypes by lazy { object : First, Second { } } +class A { + val a: First by lazy { + object : First { } + } +} + interface First interface Second diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.txt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.txt index 93a4d38f52f..a567fa316ae 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.txt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.txt @@ -5,6 +5,14 @@ private val withTwoSupertypes: withTwoSupertypes.. private val withoutType: withoutType.. public fun lazy(/*0*/ initializer: () -> T): Lazy +public final class A { + public constructor A() + public final val a: First + 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 +} + public interface First { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int