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 -> add(FirErrors.DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER.errorFactory) { firDiagnostic ->
DelegateUsesExtensionPropertyTypeParameterErrorImpl( DelegateUsesExtensionPropertyTypeParameterErrorImpl(
firSymbolBuilder.classifierBuilder.buildTypeParameterSymbol(firDiagnostic.a.fir),
firDiagnostic as KtPsiDiagnostic, firDiagnostic as KtPsiDiagnostic,
token, token,
) )
} }
add(FirErrors.DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER.warningFactory) { firDiagnostic -> add(FirErrors.DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER.warningFactory) { firDiagnostic ->
DelegateUsesExtensionPropertyTypeParameterWarningImpl( DelegateUsesExtensionPropertyTypeParameterWarningImpl(
firSymbolBuilder.classifierBuilder.buildTypeParameterSymbol(firDiagnostic.a.fir),
firDiagnostic as KtPsiDiagnostic, firDiagnostic as KtPsiDiagnostic,
token, token,
) )
@@ -1821,10 +1821,12 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
abstract class DelegateUsesExtensionPropertyTypeParameterError : KtFirDiagnostic<KtProperty>() { abstract class DelegateUsesExtensionPropertyTypeParameterError : KtFirDiagnostic<KtProperty>() {
override val diagnosticClass get() = DelegateUsesExtensionPropertyTypeParameterError::class override val diagnosticClass get() = DelegateUsesExtensionPropertyTypeParameterError::class
abstract val usedTypeParameter: KtTypeParameterSymbol
} }
abstract class DelegateUsesExtensionPropertyTypeParameterWarning : KtFirDiagnostic<KtProperty>() { abstract class DelegateUsesExtensionPropertyTypeParameterWarning : KtFirDiagnostic<KtProperty>() {
override val diagnosticClass get() = DelegateUsesExtensionPropertyTypeParameterWarning::class override val diagnosticClass get() = DelegateUsesExtensionPropertyTypeParameterWarning::class
abstract val usedTypeParameter: KtTypeParameterSymbol
} }
abstract class InitializerTypeMismatch : KtFirDiagnostic<KtProperty>() { abstract class InitializerTypeMismatch : KtFirDiagnostic<KtProperty>() {
@@ -2188,11 +2188,13 @@ internal class WrongSetterParameterTypeImpl(
) : KtFirDiagnostic.WrongSetterParameterType(), KtAbstractFirDiagnostic<KtTypeReference> ) : KtFirDiagnostic.WrongSetterParameterType(), KtAbstractFirDiagnostic<KtTypeReference>
internal class DelegateUsesExtensionPropertyTypeParameterErrorImpl( internal class DelegateUsesExtensionPropertyTypeParameterErrorImpl(
override val usedTypeParameter: KtTypeParameterSymbol,
override val firDiagnostic: KtPsiDiagnostic, override val firDiagnostic: KtPsiDiagnostic,
override val token: ValidityToken, override val token: ValidityToken,
) : KtFirDiagnostic.DelegateUsesExtensionPropertyTypeParameterError(), KtAbstractFirDiagnostic<KtProperty> ) : KtFirDiagnostic.DelegateUsesExtensionPropertyTypeParameterError(), KtAbstractFirDiagnostic<KtProperty>
internal class DelegateUsesExtensionPropertyTypeParameterWarningImpl( internal class DelegateUsesExtensionPropertyTypeParameterWarningImpl(
override val usedTypeParameter: KtTypeParameterSymbol,
override val firDiagnostic: KtPsiDiagnostic, override val firDiagnostic: KtPsiDiagnostic,
override val token: ValidityToken, override val token: ValidityToken,
) : KtFirDiagnostic.DelegateUsesExtensionPropertyTypeParameterWarning(), KtAbstractFirDiagnostic<KtProperty> ) : KtFirDiagnostic.DelegateUsesExtensionPropertyTypeParameterWarning(), KtAbstractFirDiagnostic<KtProperty>
@@ -927,7 +927,9 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
val DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER by deprecationError<KtProperty>( val DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER by deprecationError<KtProperty>(
LanguageFeature.ForbidUsingExtensionPropertyTypeParameterInDelegate, LanguageFeature.ForbidUsingExtensionPropertyTypeParameterInDelegate,
PositioningStrategy.PROPERTY_DELEGATE PositioningStrategy.PROPERTY_DELEGATE
) ) {
parameter<FirTypeParameterSymbol>("usedTypeParameter")
}
val INITIALIZER_TYPE_MISMATCH by error<KtProperty>(PositioningStrategy.PROPERTY_INITIALIZER) { val INITIALIZER_TYPE_MISMATCH by error<KtProperty>(PositioningStrategy.PROPERTY_INITIALIZER) {
parameter<ConeKotlinType>("expectedType") parameter<ConeKotlinType>("expectedType")
parameter<ConeKotlinType>("actualType") parameter<ConeKotlinType>("actualType")
@@ -508,7 +508,7 @@ object FirErrors {
val CONST_VAL_WITHOUT_INITIALIZER by error0<KtProperty>(SourceElementPositioningStrategies.CONST_MODIFIER) val CONST_VAL_WITHOUT_INITIALIZER by error0<KtProperty>(SourceElementPositioningStrategies.CONST_MODIFIER)
val CONST_VAL_WITH_NON_CONST_INITIALIZER by error0<KtExpression>() val CONST_VAL_WITH_NON_CONST_INITIALIZER by error0<KtExpression>()
val WRONG_SETTER_PARAMETER_TYPE by error2<KtTypeReference, ConeKotlinType, ConeKotlinType>() 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 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 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) 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 delegate = declaration.delegate.safeAs<FirFunctionCall>() ?: return
val parameters = declaration.typeParameters.mapTo(hashSetOf()) { it.symbol } 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, usedTypeParameterSymbol, context)
reporter.reportOn(declaration.source, FirErrors.DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER, context)
}
} }
private fun ConeKotlinType.containsTypeParameterFrom( private fun ConeKotlinType.findUsedTypeParameterSymbol(
parameters: HashSet<FirTypeParameterSymbol>, parameters: HashSet<FirTypeParameterSymbol>,
delegate: FirFunctionCall, delegate: FirFunctionCall,
context: CheckerContext, context: CheckerContext,
reporter: DiagnosticReporter, reporter: DiagnosticReporter,
): Boolean { ): FirTypeParameterSymbol? {
for (it in typeArguments) { for (it in typeArguments) {
val theType = it.type ?: continue val theType = it.type ?: continue
val symbol = theType.toSymbol(context.session) val symbol = theType.toSymbol(context.session) as? FirTypeParameterSymbol
if ( if (symbol in parameters) return symbol
symbol in parameters || val usedTypeParameterSymbol = theType.findUsedTypeParameterSymbol(parameters, delegate, context, reporter)
theType.containsTypeParameterFrom(parameters, delegate, context, reporter) if (usedTypeParameterSymbol != null) {
) { return usedTypeParameterSymbol
return true
} }
} }
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_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(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(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_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_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_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_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(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") map.put(REDUNDANT_OPEN_IN_INTERFACE, "Modifier 'open' is redundant for abstract interface members")
@@ -1450,7 +1450,8 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
) )
map.put( map.put(
DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER, 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(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") map.put(GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, "Getter visibility must be the same as property visibility")