FIR Checker: check AMBIGUOUS_ANONYMOUS_TYPE_INFERRED

Also change
org.jetbrains.kotlin.fir.types.TypeUtilsKt#hideLocalTypeIfNeeded to skip
approximating anonymous objects if there are multiple super type refs so
that resolution behaves the same (for uncompilable code).

Note that this change does not implement check for
ApproximateAnonymousReturnTypesInPrivateInlineFunctions as the check is
already turned on in 1.5 and will likely not needed when FIR becomes
stable.
This commit is contained in:
Tianyu Geng
2021-09-01 13:30:02 -07:00
committed by teamcityserver
parent 6432388778
commit 76e192fc8a
14 changed files with 149 additions and 72 deletions
@@ -1960,6 +1960,15 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.AMBIGUOUS_ANONYMOUS_TYPE_INFERRED) { firDiagnostic ->
AmbiguousAnonymousTypeInferredImpl(
firDiagnostic.a.map { coneKotlinType ->
firSymbolBuilder.typeBuilder.buildKtType(coneKotlinType)
},
firDiagnostic as FirPsiDiagnostic,
token,
)
}
add(FirErrors.MANY_IMPL_MEMBER_NOT_IMPLEMENTED) { firDiagnostic ->
ManyImplMemberNotImplementedImpl(
firSymbolBuilder.classifierBuilder.buildClassLikeSymbol(firDiagnostic.a.fir),
@@ -1397,6 +1397,11 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
abstract val invisibleDeclaration: KtCallableSymbol
}
abstract class AmbiguousAnonymousTypeInferred : KtFirDiagnostic<KtDeclaration>() {
override val diagnosticClass get() = AmbiguousAnonymousTypeInferred::class
abstract val superTypes: List<KtType>
}
abstract class ManyImplMemberNotImplemented : KtFirDiagnostic<KtClassOrObject>() {
override val diagnosticClass get() = ManyImplMemberNotImplemented::class
abstract val classOrObject: KtClassLikeSymbol
@@ -2232,6 +2232,14 @@ internal class InvisibleAbstractMemberFromSuperWarningImpl(
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class AmbiguousAnonymousTypeInferredImpl(
override val superTypes: List<KtType>,
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,
) : KtFirDiagnostic.AmbiguousAnonymousTypeInferred(), KtAbstractFirDiagnostic<KtDeclaration> {
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class ManyImplMemberNotImplementedImpl(
override val classOrObject: KtClassLikeSymbol,
override val missingDeclaration: KtCallableSymbol,