diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeAliasExpander.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeAliasExpander.kt index 96d8b3f26d7..443d44c41d2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeAliasExpander.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeAliasExpander.kt @@ -112,6 +112,11 @@ class TypeAliasExpander( recursionDepth: Int ): TypeProjection { val type = originalProjection.type + + if (!type.requiresTypeAliasExpansion()) { + return originalProjection + } + val typeConstructor = type.constructor val typeDescriptor = typeConstructor.declarationDescriptor diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeAliasExpansion.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeAliasExpansion.kt index 8b68e51c150..a58ca27c061 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeAliasExpansion.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeAliasExpansion.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.resolve +import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.types.KotlinType @@ -57,7 +58,16 @@ class TypeAliasExpansion private constructor( } fun KotlinType.dependsOnTypeAliasParameters(): Boolean = - TypeUtils.contains(this) { type -> - val constructorDeclaration = type.constructor.declarationDescriptor - constructorDeclaration is TypeParameterDescriptor && constructorDeclaration.containingDeclaration is TypeAliasDescriptor - } \ No newline at end of file + TypeUtils.contains(this) { + it.constructor.declarationDescriptor?.isTypeAliasParameter() ?: false + } + +fun ClassifierDescriptor.isTypeAliasParameter(): Boolean = + this is TypeParameterDescriptor && containingDeclaration is TypeAliasDescriptor + +fun KotlinType.requiresTypeAliasExpansion(): Boolean = + TypeUtils.contains(this) { + it.constructor.declarationDescriptor?.let { + it is TypeAliasDescriptor || it is TypeParameterDescriptor + } + } diff --git a/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasRHS.kt b/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasRHS.kt index af9f7335965..003d367dc6a 100644 --- a/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasRHS.kt +++ b/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasRHS.kt @@ -5,8 +5,8 @@ class TColl> typealias TCErr = TCollAny> typealias TCErr2 = TCErr -fun testType1(x: TCErr) {} +fun testType1(x: TCErr) {} val testCtor1 = TCErr() -fun testType2(x: TCErr2) {} +fun testType2(x: TCErr2) {} val testCtor2 = TCErr2()