FIR2IR: make enum with abstract members from interfaces abstract

Related to KT-55828
This commit is contained in:
Mikhail Glukhikh
2023-02-01 10:56:15 +01:00
parent 89c42e20c9
commit 6d642c88f5
7 changed files with 32 additions and 15 deletions
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.resolve.providers.firProvider
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
import org.jetbrains.kotlin.fir.resolve.providers.toSymbol
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.fir.symbols.Fir2IrClassSymbol
import org.jetbrains.kotlin.fir.symbols.Fir2IrEnumEntrySymbol
@@ -197,15 +198,39 @@ class Fir2IrClassifierStorage(
declarations.any { it is FirCallableDeclaration && it.modality == Modality.ABSTRACT } -> {
Modality.ABSTRACT
}
declarations.any { it is FirEnumEntry && it.initializer != null } -> {
Modality.OPEN
}
else -> {
declarations.none { it is FirEnumEntry && it.initializer != null } -> {
Modality.FINAL
}
hasAbstractMembersInScope() -> {
Modality.ABSTRACT
}
else -> {
Modality.OPEN
}
}
}
private fun FirRegularClass.hasAbstractMembersInScope(): Boolean {
val scope = unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
val names = scope.getCallableNames()
var hasAbstract = false
for (name in names) {
scope.processFunctionsByName(name) {
if (it.isAbstract) {
hasAbstract = true
}
}
if (hasAbstract) return true
scope.processPropertiesByName(name) {
if (it.isAbstract) {
hasAbstract = true
}
}
if (hasAbstract) return true
}
return false
}
// This function is called when we refer local class earlier than we reach its declaration
// This can happen e.g. when implicit return type has a local class constructor
private fun createLocalIrClassOnTheFly(klass: FirClass): IrClass {