Don't expand types that don't contain type aliases or type parameters.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@ class TColl<T, C : Collection<T>>
|
||||
typealias TCErr = TColl<String, <!UPPER_BOUND_VIOLATED!>Any<!>>
|
||||
typealias TCErr2 = TCErr
|
||||
|
||||
fun testType1(x: <!UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION!>TCErr<!>) {}
|
||||
fun testType1(x: TCErr) {}
|
||||
val testCtor1 = <!UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION!>TCErr()<!>
|
||||
|
||||
fun testType2(x: <!UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION!>TCErr2<!>) {}
|
||||
fun testType2(x: TCErr2) {}
|
||||
val testCtor2 = <!UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION!>TCErr2()<!>
|
||||
|
||||
Reference in New Issue
Block a user