[FIR][K/N] Don't use FIR internals in FirNativeObjCOverrideInitChecker
^KT-61564
This commit is contained in:
committed by
Space Team
parent
ad9f7bf90e
commit
55a41961d3
+18
-11
@@ -18,28 +18,35 @@ import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.getSuperClassSymbolOrAny
|
||||
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.declaredMemberScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.NativeStandardInteropNames.objCOverrideInitClassId
|
||||
|
||||
object FirNativeObjCOverrideInitChecker : FirClassChecker() {
|
||||
@OptIn(SymbolInternals::class)
|
||||
override fun check(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val session = context.session
|
||||
|
||||
fun FirConstructor.overridesConstructor(other: FirConstructor): Boolean {
|
||||
if (valueParameters.size != other.valueParameters.size)
|
||||
fun FirClassSymbol<*>.constructors(session: FirSession): List<FirConstructorSymbol> {
|
||||
val result = mutableListOf<FirConstructorSymbol>()
|
||||
session.declaredMemberScope(this, memberRequiredPhase = null).processDeclaredConstructors { result += it }
|
||||
return result
|
||||
}
|
||||
|
||||
fun FirConstructorSymbol.overridesConstructor(other: FirConstructorSymbol): Boolean {
|
||||
val aParams = this.valueParameterSymbols
|
||||
val bParams = other.valueParameterSymbols
|
||||
if (aParams.size != bParams.size)
|
||||
return false
|
||||
return valueParameters.zip(other.valueParameters).all { (thisParameter, otherParameter) ->
|
||||
thisParameter.name == otherParameter.name && thisParameter.returnTypeRef.coneType == otherParameter.returnTypeRef.coneType
|
||||
return aParams.zip(bParams).all { (thisParameter, otherParameter) ->
|
||||
thisParameter.name == otherParameter.name && thisParameter.resolvedReturnType == otherParameter.resolvedReturnType
|
||||
}
|
||||
}
|
||||
|
||||
fun checkCanGenerateOverrideInit(firClass: FirClass, constructor: FirConstructor) {
|
||||
val superClass = (firClass as FirRegularClass).symbol.getSuperClassSymbolOrAny(session)
|
||||
val superConstructors = superClass.fir.constructors(session).filter {
|
||||
constructor.overridesConstructor(it.fir)
|
||||
val superConstructors = superClass.constructors(session).filter {
|
||||
constructor.symbol.overridesConstructor(it)
|
||||
}.toList()
|
||||
|
||||
val superConstructor: FirConstructorSymbol = superConstructors.singleOrNull() ?: run {
|
||||
@@ -60,11 +67,11 @@ object FirNativeObjCOverrideInitChecker : FirClassChecker() {
|
||||
return
|
||||
}
|
||||
|
||||
val initMethod = superConstructor.fir.getObjCInitMethod(session, ScopeSession())!!
|
||||
val initMethod = superConstructor.getObjCInitMethod(session, ScopeSession())!!
|
||||
|
||||
// Remove fake overrides of this init method, also check for explicit overriding:
|
||||
firClass.declarations.forEach {
|
||||
if (it is FirSimpleFunction && initMethod.symbol in it.getOverriddenSymbols(context) && !it.isSubstitutionOrIntersectionOverride) {
|
||||
if (it is FirSimpleFunction && initMethod in it.getOverriddenSymbols(context) && !it.isSubstitutionOrIntersectionOverride) {
|
||||
reporter.reportOn(
|
||||
constructor.source,
|
||||
FirNativeErrors.CONSTRUCTOR_OVERRIDES_ALREADY_OVERRIDDEN_OBJC_INITIALIZER,
|
||||
|
||||
Reference in New Issue
Block a user