[FIR] Properly substitute arguments of error types

This commit is contained in:
Dmitriy Novozhilov
2022-10-03 16:36:07 +03:00
committed by Space Team
parent edbf199f84
commit e7148daad2
2 changed files with 8 additions and 5 deletions
@@ -59,7 +59,6 @@ abstract class AbstractConeSubstitutor(protected val typeContext: ConeTypeContex
private fun ConeKotlinType.substituteRecursive(): ConeKotlinType? {
return when (this) {
is ConeErrorType -> return null
is ConeClassLikeType -> this.substituteArguments()
is ConeLookupTagBasedType -> return null
is ConeFlexibleType -> this.substituteBounds()?.let {
@@ -131,12 +130,10 @@ abstract class AbstractConeSubstitutor(protected val typeContext: ConeTypeContex
return null
}
private fun ConeKotlinType.substituteArguments(): ConeKotlinType? {
private fun ConeClassLikeType.substituteArguments(): ConeKotlinType? {
val newArguments by lazy { arrayOfNulls<ConeTypeProjection>(typeArguments.size) }
var initialized = false
require(this is ConeClassLikeType) { "Unknown type to substitute: $this, ${this::class}" }
for ((index, typeArgument) in this.typeArguments.withIndex()) {
newArguments[index] = substituteArgument(typeArgument, index)?.also {
initialized = true
@@ -157,6 +154,12 @@ abstract class AbstractConeSubstitutor(protected val typeContext: ConeTypeContex
nullability.isNullable,
attributes
)
is ConeErrorType -> ConeErrorType(
diagnostic,
isUninferredParameter,
newArguments as Array<ConeTypeProjection>,
attributes
)
else -> error("Unknown class-like type to substitute: $this, ${this::class}")
}
}