[FIR] Use typeArgumentsList from delegatedTypeRef instead of accessing via tree
This commit is contained in:
+12
-7
@@ -5,27 +5,32 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.expression
|
||||
|
||||
import org.jetbrains.kotlin.KtNodeTypes.TYPE_ARGUMENT_LIST
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.getChild
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.FirUserTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes.TYPE_ELEMENT_TYPES
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
object FirSuperReferenceChecker : FirQualifiedAccessExpressionChecker() {
|
||||
override fun check(expression: FirQualifiedAccessExpression, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val superReference = expression.calleeReference.safeAs<FirSuperReference>()?.takeIf { it.hadExplicitTypeInSource() } ?: return
|
||||
|
||||
val typeArgumentListSource = superReference.superTypeRef.source?.getChild(TYPE_ELEMENT_TYPES)?.getChild(TYPE_ARGUMENT_LIST)
|
||||
val superType = superReference.superTypeRef.coneType
|
||||
if (typeArgumentListSource != null && superType !is ConeKotlinErrorType && superType.typeArguments.all { it !is ConeKotlinErrorType }) {
|
||||
reporter.reportOn(typeArgumentListSource, FirErrors.TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER, context)
|
||||
val superTypeRef = superReference.superTypeRef
|
||||
val delegatedTypeRef = (superTypeRef as? FirResolvedTypeRef)?.delegatedTypeRef as? FirUserTypeRef ?: return
|
||||
val typeArgumentList = delegatedTypeRef.qualifier.firstOrNull()?.typeArgumentList ?: return
|
||||
val superType = superTypeRef.coneType
|
||||
|
||||
if (superType !is ConeKotlinErrorType &&
|
||||
typeArgumentList.typeArguments.isNotEmpty() &&
|
||||
superType.typeArguments.all { it !is ConeKotlinErrorType }
|
||||
) {
|
||||
reporter.reportOn(typeArgumentList.source, FirErrors.TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -226,7 +226,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
||||
* DiagnosticsTestGenerated$Tests$ThisAndSuper.testGenericQualifiedSuperOverridden
|
||||
* DiagnosticsTestGenerated$Tests$ThisAndSuper.testQualifiedSuperOverridden
|
||||
*/
|
||||
val actualSuperTypeRef = actualSuperType?.toFirResolvedTypeRef(superTypeRef.source) ?: buildErrorTypeRef {
|
||||
val actualSuperTypeRef = actualSuperType?.toFirResolvedTypeRef(superTypeRef.source, superTypeRef) ?: buildErrorTypeRef {
|
||||
source = superTypeRef.source
|
||||
diagnostic = ConeSimpleDiagnostic("Not a super type", DiagnosticKind.NotASupertype)
|
||||
}
|
||||
|
||||
@@ -197,16 +197,19 @@ fun ConeKotlinType.toSymbol(session: FirSession): FirBasedSymbol<*>? {
|
||||
|
||||
fun ConeKotlinType.toFirResolvedTypeRef(
|
||||
source: FirSourceElement? = null,
|
||||
delegatedTypeRef: FirTypeRef? = null
|
||||
): FirResolvedTypeRef {
|
||||
return if (this is ConeKotlinErrorType) {
|
||||
buildErrorTypeRef {
|
||||
this.source = source
|
||||
diagnostic = this@toFirResolvedTypeRef.diagnostic
|
||||
this.delegatedTypeRef = delegatedTypeRef
|
||||
}
|
||||
} else {
|
||||
buildResolvedTypeRef {
|
||||
this.source = source
|
||||
type = this@toFirResolvedTypeRef
|
||||
this.delegatedTypeRef = delegatedTypeRef
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user