[FIR] Simplify getSingleExpectForActualOrNull
When compatibleOnly == false, the logic was equivalent to returning singleOrNull. The only call-site with compatibleOnly = true was FirElementSerializer, but after the fix for KT-59613, the map will never contain multiple entries when one of the entries is compatible. Assuming that we only run serialization on green code, the map will either contain one compatible entry or no entries which makes the additional check redundant.
This commit is contained in:
committed by
Space Team
parent
b68962018c
commit
1d3a127f52
+1
-1
@@ -702,7 +702,7 @@ class FirElementSerializer private constructor(
|
||||
val builder = ProtoBuf.ValueParameter.newBuilder()
|
||||
|
||||
val declaresDefaultValue = parameter.defaultValue != null ||
|
||||
function.symbol.getSingleExpectForActualOrNull(compatibleOnly = true).containsDefaultValue(index)
|
||||
function.symbol.getSingleExpectForActualOrNull().containsDefaultValue(index)
|
||||
|
||||
val flags = Flags.getValueParameterFlags(
|
||||
additionalAnnotations.isNotEmpty()
|
||||
|
||||
+4
-16
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCompatibility
|
||||
import org.jetbrains.kotlin.resolve.multiplatform.compatible
|
||||
|
||||
private object ExpectForActualAttributeKey : FirDeclarationDataKey()
|
||||
|
||||
@@ -19,22 +18,11 @@ typealias ExpectForActualData = Map<ExpectActualCompatibility<FirBasedSymbol<*>>
|
||||
@SymbolInternals
|
||||
var FirDeclaration.expectForActual: ExpectForActualData? by FirDeclarationDataRegistry.data(ExpectForActualAttributeKey)
|
||||
|
||||
fun FirFunctionSymbol<*>.getSingleExpectForActualOrNull(compatibleOnly: Boolean = false) =
|
||||
(this as FirBasedSymbol<*>).getSingleExpectForActualOrNull(compatibleOnly) as? FirFunctionSymbol<*>
|
||||
fun FirFunctionSymbol<*>.getSingleExpectForActualOrNull(): FirFunctionSymbol<*>? =
|
||||
(this as FirBasedSymbol<*>).getSingleExpectForActualOrNull() as? FirFunctionSymbol<*>
|
||||
|
||||
fun FirBasedSymbol<*>.getSingleExpectForActualOrNull(compatibleOnly: Boolean = false): FirBasedSymbol<*>? {
|
||||
val expectForActual = expectForActual ?: return null
|
||||
var actuals: List<FirBasedSymbol<*>>? = null
|
||||
for ((key, item) in expectForActual) {
|
||||
if (!compatibleOnly || key.compatible) {
|
||||
if (actuals == null) {
|
||||
actuals = item
|
||||
} else {
|
||||
return null // Exit if there are more than one list with actuals
|
||||
}
|
||||
}
|
||||
}
|
||||
return actuals?.singleOrNull()
|
||||
fun FirBasedSymbol<*>.getSingleExpectForActualOrNull(): FirBasedSymbol<*>? {
|
||||
return expectForActual?.values?.singleOrNull()?.singleOrNull()
|
||||
}
|
||||
|
||||
val FirBasedSymbol<*>.expectForActual: ExpectForActualData?
|
||||
|
||||
Reference in New Issue
Block a user