FIR: render <T> name for DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER

Related to KT-50183
This commit is contained in:
Mikhail Glukhikh
2022-01-10 19:41:58 +03:00
parent a4f74f60d9
commit beb2957726
7 changed files with 27 additions and 20 deletions
@@ -2572,12 +2572,14 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
}
add(FirErrors.DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER.errorFactory) { firDiagnostic ->
DelegateUsesExtensionPropertyTypeParameterErrorImpl(
firSymbolBuilder.classifierBuilder.buildTypeParameterSymbol(firDiagnostic.a.fir),
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirErrors.DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER.warningFactory) { firDiagnostic ->
DelegateUsesExtensionPropertyTypeParameterWarningImpl(
firSymbolBuilder.classifierBuilder.buildTypeParameterSymbol(firDiagnostic.a.fir),
firDiagnostic as KtPsiDiagnostic,
token,
)
@@ -1821,10 +1821,12 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
abstract class DelegateUsesExtensionPropertyTypeParameterError : KtFirDiagnostic<KtProperty>() {
override val diagnosticClass get() = DelegateUsesExtensionPropertyTypeParameterError::class
abstract val usedTypeParameter: KtTypeParameterSymbol
}
abstract class DelegateUsesExtensionPropertyTypeParameterWarning : KtFirDiagnostic<KtProperty>() {
override val diagnosticClass get() = DelegateUsesExtensionPropertyTypeParameterWarning::class
abstract val usedTypeParameter: KtTypeParameterSymbol
}
abstract class InitializerTypeMismatch : KtFirDiagnostic<KtProperty>() {
@@ -2188,11 +2188,13 @@ internal class WrongSetterParameterTypeImpl(
) : KtFirDiagnostic.WrongSetterParameterType(), KtAbstractFirDiagnostic<KtTypeReference>
internal class DelegateUsesExtensionPropertyTypeParameterErrorImpl(
override val usedTypeParameter: KtTypeParameterSymbol,
override val firDiagnostic: KtPsiDiagnostic,
override val token: ValidityToken,
) : KtFirDiagnostic.DelegateUsesExtensionPropertyTypeParameterError(), KtAbstractFirDiagnostic<KtProperty>
internal class DelegateUsesExtensionPropertyTypeParameterWarningImpl(
override val usedTypeParameter: KtTypeParameterSymbol,
override val firDiagnostic: KtPsiDiagnostic,
override val token: ValidityToken,
) : KtFirDiagnostic.DelegateUsesExtensionPropertyTypeParameterWarning(), KtAbstractFirDiagnostic<KtProperty>
@@ -927,7 +927,9 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
val DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER by deprecationError<KtProperty>(
LanguageFeature.ForbidUsingExtensionPropertyTypeParameterInDelegate,
PositioningStrategy.PROPERTY_DELEGATE
)
) {
parameter<FirTypeParameterSymbol>("usedTypeParameter")
}
val INITIALIZER_TYPE_MISMATCH by error<KtProperty>(PositioningStrategy.PROPERTY_INITIALIZER) {
parameter<ConeKotlinType>("expectedType")
parameter<ConeKotlinType>("actualType")
@@ -508,7 +508,7 @@ object FirErrors {
val CONST_VAL_WITHOUT_INITIALIZER by error0<KtProperty>(SourceElementPositioningStrategies.CONST_MODIFIER)
val CONST_VAL_WITH_NON_CONST_INITIALIZER by error0<KtExpression>()
val WRONG_SETTER_PARAMETER_TYPE by error2<KtTypeReference, ConeKotlinType, ConeKotlinType>()
val DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER by deprecationError0<KtProperty>(ForbidUsingExtensionPropertyTypeParameterInDelegate, SourceElementPositioningStrategies.PROPERTY_DELEGATE)
val DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER by deprecationError1<KtProperty, FirTypeParameterSymbol>(ForbidUsingExtensionPropertyTypeParameterInDelegate, SourceElementPositioningStrategies.PROPERTY_DELEGATE)
val INITIALIZER_TYPE_MISMATCH by error3<KtProperty, ConeKotlinType, ConeKotlinType, Boolean>(SourceElementPositioningStrategies.PROPERTY_INITIALIZER)
val GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY by error0<KtModifierListOwner>(SourceElementPositioningStrategies.VISIBILITY_MODIFIER)
val SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY by error0<KtModifierListOwner>(SourceElementPositioningStrategies.VISIBILITY_MODIFIER)
@@ -23,31 +23,29 @@ object FirDelegateUsesExtensionPropertyTypeParameterChecker : FirPropertyChecker
val delegate = declaration.delegate.safeAs<FirFunctionCall>() ?: return
val parameters = declaration.typeParameters.mapTo(hashSetOf()) { it.symbol }
val shouldReportError = delegate.typeRef.coneType.containsTypeParameterFrom(parameters, delegate, context, reporter)
val usedTypeParameterSymbol = delegate.typeRef.coneType.findUsedTypeParameterSymbol(parameters, delegate, context, reporter)
?: return
if (shouldReportError) {
reporter.reportOn(declaration.source, FirErrors.DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER, context)
}
reporter.reportOn(declaration.source, FirErrors.DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER, usedTypeParameterSymbol, context)
}
private fun ConeKotlinType.containsTypeParameterFrom(
private fun ConeKotlinType.findUsedTypeParameterSymbol(
parameters: HashSet<FirTypeParameterSymbol>,
delegate: FirFunctionCall,
context: CheckerContext,
reporter: DiagnosticReporter,
): Boolean {
): FirTypeParameterSymbol? {
for (it in typeArguments) {
val theType = it.type ?: continue
val symbol = theType.toSymbol(context.session)
val symbol = theType.toSymbol(context.session) as? FirTypeParameterSymbol
if (
symbol in parameters ||
theType.containsTypeParameterFrom(parameters, delegate, context, reporter)
) {
return true
if (symbol in parameters) return symbol
val usedTypeParameterSymbol = theType.findUsedTypeParameterSymbol(parameters, delegate, context, reporter)
if (usedTypeParameterSymbol != null) {
return usedTypeParameterSymbol
}
}
return false
return null
}
}
@@ -890,10 +890,10 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
map.put(DEPRECATED_MODIFIER_PAIR, "Modifier ''{0}'' is deprecated in presence of ''{1}''", TO_STRING, TO_STRING)
map.put(DEPRECATED_MODIFIER_FOR_TARGET, "Modifier ''{0}'' is deprecated for ''{1}''", TO_STRING, STRING)
map.put(REDUNDANT_MODIFIER_FOR_TARGET, "Modifier ''{0}'' is redundant for ''{1}''", TO_STRING, STRING)
map.put(NO_EXPLICIT_VISIBILITY_IN_API_MODE, "Visibility must be specified in explicit API mode");
map.put(NO_EXPLICIT_RETURN_TYPE_IN_API_MODE, "Return type must be specified in explicit API mode");
map.put(NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING, "Visibility must be specified in explicit API mode");
map.put(NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_WARNING, "Return type must be specified in explicit API mode");
map.put(NO_EXPLICIT_VISIBILITY_IN_API_MODE, "Visibility must be specified in explicit API mode")
map.put(NO_EXPLICIT_RETURN_TYPE_IN_API_MODE, "Return type must be specified in explicit API mode")
map.put(NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING, "Visibility must be specified in explicit API mode")
map.put(NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_WARNING, "Return type must be specified in explicit API mode")
map.put(INCOMPATIBLE_MODIFIERS, "Modifier ''{0}'' is incompatible with ''{1}''", TO_STRING, TO_STRING)
map.put(REDUNDANT_OPEN_IN_INTERFACE, "Modifier 'open' is redundant for abstract interface members")
@@ -1450,7 +1450,8 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
)
map.put(
DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER,
"It's forbidden using extension property type parameter in delegate"
"It''s forbidden using extension property type parameter ''{0}'' in delegate",
SYMBOL
)
map.put(INITIALIZER_TYPE_MISMATCH, "Initializer type mismatch: expected {0}, actual {1}", RENDER_TYPE, RENDER_TYPE, NOT_RENDERED)
map.put(GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, "Getter visibility must be the same as property visibility")