[AA] Fix rendering for type variable with "Type is not inferred"

It is required to show type variable name instead of ERROR in completion
^KTIJ-20913
This commit is contained in:
aleksandrina-streltsova
2023-03-14 11:08:27 +02:00
committed by Space Team
parent bccf1aaff0
commit 34c739789f
4 changed files with 11 additions and 1 deletions
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
import org.jetbrains.kotlin.analysis.api.types.KtTypeErrorType
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
import org.jetbrains.kotlin.fir.diagnostics.ConeCannotInferTypeParameterType
import org.jetbrains.kotlin.fir.diagnostics.ConeTypeVariableTypeIsNotInferred
import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.renderForDebugging
@@ -29,6 +30,7 @@ internal class KtFirTypeErrorType(
override fun tryRenderAsNonErrorType(): String? = withValidityAssertion {
when (val diagnostic = coneType.diagnostic) {
is ConeCannotInferTypeParameterType -> diagnostic.typeParameter.name.asString()
is ConeTypeVariableTypeIsNotInferred -> diagnostic.typeVariableType.lookupTag.debugName
else -> null
}
}
@@ -110,6 +110,7 @@ private fun ConeDiagnostic.toKtDiagnostic(
is ConeDestructuringDeclarationsOnTopLevel -> FirSyntaxErrors.SYNTAX.createOn(source)
is ConeCannotInferTypeParameterType -> FirErrors.CANNOT_INFER_PARAMETER_TYPE.createOn(source)
is ConeCannotInferValueParameterType -> FirErrors.CANNOT_INFER_PARAMETER_TYPE.createOn(source)
is ConeTypeVariableTypeIsNotInferred -> FirErrors.INFERENCE_ERROR.createOn(qualifiedAccessSource ?: source)
is ConeInstanceAccessBeforeSuperCall -> FirErrors.INSTANCE_ACCESS_BEFORE_SUPER_CALL.createOn(source, this.target)
is ConeStubDiagnostic -> null
is ConeIntermediateDiagnostic -> null
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.substitution
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeTypeVariableTypeIsNotInferred
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
@@ -320,7 +321,7 @@ class ConeStubAndTypeVariableToErrorTypeSubstitutor(
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
return when (type) {
is ConeTypeVariableType -> ConeErrorType(
ConeSimpleDiagnostic("Type for ${type.lookupTag.debugName} is not inferred", DiagnosticKind.InferenceError),
ConeTypeVariableTypeIsNotInferred(type),
isUninferredParameter = true
)
is ConeStubType -> runIf(type.constructor in stubTypesToReplace) {
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeTypeVariableType
import org.jetbrains.kotlin.name.Name
class ConeSimpleDiagnostic(override val reason: String, val kind: DiagnosticKind = DiagnosticKind.Other) : ConeDiagnostic
@@ -34,6 +35,11 @@ class ConeCannotInferValueParameterType(
override val reason: String = "Cannot infer type for parameter ${valueParameter.name}"
) : ConeDiagnostic
class ConeTypeVariableTypeIsNotInferred(
val typeVariableType: ConeTypeVariableType,
override val reason: String = "Type for ${typeVariableType.lookupTag.debugName} is not inferred"
) : ConeDiagnostic
class ConeUnderscoreUsageWithoutBackticks(source: KtSourceElement) : ConeDiagnosticWithSource(source) {
override val reason: String get() = "Names _, __, ___, ... can be used only in back-ticks (`_`, `__`, `___`, ...)"
}