[FIR] KT-54692: Fix compiler crash on UInt.shl

Merge-request: KT-MR-7513
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
This commit is contained in:
Nikolay Lunyak
2022-10-27 10:40:06 +00:00
committed by Space Team
parent 34478b84cd
commit 7e323f8ac6
14 changed files with 86 additions and 4 deletions
@@ -19,5 +19,9 @@ object ConvertibleIntegerOperators {
"inv", "unaryPlus", "unaryMinus"
).toNameSet()
val binaryOperatorsWithSignedArgument: Set<Name> = listOf(
"shl", "shr", "ushr",
).toNameSet()
private fun List<String>.toNameSet(): Set<Name> = mapTo(mutableSetOf()) { Name.identifier(it) }
}
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
import org.jetbrains.kotlin.fir.scopes.getFunctions
import org.jetbrains.kotlin.fir.scopes.impl.ConvertibleIntegerOperators.binaryOperatorsWithSignedArgument
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.*
@@ -46,6 +47,7 @@ class FirIntegerConstantOperatorScope(
if (!isUnaryOperator && !isBinaryOperator) {
return baseScope.processFunctionsByName(name, processor)
}
val requiresUnsignedOperand = isUnsigned && name !in binaryOperatorsWithSignedArgument
val wrappedSymbol = mappedFunctions.getOrPut(name) {
val allFunctions = baseScope.getFunctions(name)
val functionSymbol = allFunctions.first {
@@ -53,7 +55,7 @@ class FirIntegerConstantOperatorScope(
if (isUnaryOperator) return@first true
val coneType = it.fir.valueParameters.first().returnTypeRef.coneType
if (isUnsigned) {
if (requiresUnsignedOperand) {
coneType.isUInt
} else {
coneType.isInt