From e7148daad2f207e7e0dc58245235573bc554f8c6 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 3 Oct 2022 16:36:07 +0300 Subject: [PATCH] [FIR] Properly substitute arguments of error types --- .../resolve/references/referenceToExtension.fir.txt | 2 +- .../kotlin/fir/resolve/substitution/Substitutors.kt | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.fir.txt b/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.fir.txt index 3b8add5ef49..61a03723943 100644 --- a/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.fir.txt @@ -41,7 +41,7 @@ FILE: referenceToExtension.kt public final fun test_2(): R|kotlin/Unit| { lval extensionValRef: R|kotlin/reflect/KProperty1, GenericTest.A>| = Q|GenericTest.B|::R|/GenericTest.extensionVal| - lval extensionFunRef: R|kotlin/reflect/KFunction1, GenericTest.A>| = Q|GenericTest.B|::R|/GenericTest.extensionFun| + lval extensionFunRef: R|@ExtensionFunctionType kotlin/reflect/KFunction1, GenericTest.A>| = Q|GenericTest.B|::R|/GenericTest.extensionFun| } } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt index 6a5314776ac..716250f8b25 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt @@ -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(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, + attributes + ) else -> error("Unknown class-like type to substitute: $this, ${this::class}") } }