[FIR] Support constant unary operators for integer literal operators
^KT-38895
This commit is contained in:
committed by
teamcity
parent
52b72a7dac
commit
1591518cf6
+9
-5
@@ -5,15 +5,19 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.scopes.impl
|
||||
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
|
||||
object ConvertibleIntegerOperators {
|
||||
val operatorsNames: Set<Name> = listOf(
|
||||
val binaryOperatorsNames: Set<Name> = listOf(
|
||||
"plus", "minus", "times", "div", "rem",
|
||||
"and", "or", "xor",
|
||||
"shl", "shr", "ushr"
|
||||
).mapTo(mutableSetOf()) { Name.identifier(it) }
|
||||
).toNameSet()
|
||||
|
||||
// Constant conversion for those unary operators works only for signed integers
|
||||
val unaryOperatorNames: Set<Name> = listOf(
|
||||
"inv", "unaryPlus", "unaryMinus"
|
||||
).toNameSet()
|
||||
|
||||
private fun List<String>.toNameSet(): Set<Name> = mapTo(mutableSetOf()) { Name.identifier(it) }
|
||||
}
|
||||
|
||||
+7
-1
@@ -40,12 +40,18 @@ class FirIntegerConstantOperatorScope(
|
||||
private val mappedFunctions = mutableMapOf<Name, FirNamedFunctionSymbol>()
|
||||
|
||||
override fun processFunctionsByName(name: Name, processor: (FirNamedFunctionSymbol) -> Unit) {
|
||||
if (name !in ConvertibleIntegerOperators.operatorsNames) {
|
||||
// Constant conversion for those unary operators works only for signed integers
|
||||
val isUnaryOperator = !isUnsigned && (name in ConvertibleIntegerOperators.unaryOperatorNames)
|
||||
val isBinaryOperator = name in ConvertibleIntegerOperators.binaryOperatorsNames
|
||||
if (!isUnaryOperator && !isBinaryOperator) {
|
||||
return baseScope.processFunctionsByName(name, processor)
|
||||
}
|
||||
val wrappedSymbol = mappedFunctions.getOrPut(name) {
|
||||
val allFunctions = baseScope.getFunctions(name)
|
||||
val functionSymbol = allFunctions.first {
|
||||
// unary operators have only one overload
|
||||
if (isUnaryOperator) return@first true
|
||||
|
||||
val coneType = it.fir.valueParameters.first().returnTypeRef.coneType
|
||||
if (isUnsigned) {
|
||||
coneType.isUInt
|
||||
|
||||
Reference in New Issue
Block a user