diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt index 2e3ca6240ea..3b3dee072ff 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt @@ -408,17 +408,7 @@ class ExpressionsConverter( ) { getAsFirExpression(this) } } val receiver = getAsFirExpression(argument, "No operand") - if (operationToken == PLUS || operationToken == MINUS) { - if (receiver is FirConstExpression<*> && receiver.kind == ConstantValueKind.IntegerLiteral) { - val value = receiver.value as Long - val convertedValue = when (operationToken) { - MINUS -> -value - PLUS -> value - else -> error("Should not be here") - } - return buildConstExpression(unaryExpression.toFirSourceElement(), ConstantValueKind.IntegerLiteral, convertedValue) - } - } + convertUnaryPlusMinusCallOnIntegerLiteralIfNecessary(unaryExpression, receiver, operationToken)?.let { return it } buildFunctionCall { source = unaryExpression.toFirSourceElement() calleeReference = buildSimpleNamedReference { diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 78e64feec60..4ccd4fef4c4 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -2239,21 +2239,9 @@ open class RawFirBuilder( } val receiver = argument.toFirExpression("No operand") - if (operationToken == PLUS || operationToken == MINUS) { - if (receiver is FirConstExpression<*> && receiver.kind == ConstantValueKind.IntegerLiteral) { - val value = receiver.value as Long - val convertedValue = when (operationToken) { - MINUS -> -value - PLUS -> value - else -> error("Should not be here") - } - return buildConstExpression( - expression.toKtPsiSourceElement(), - ConstantValueKind.IntegerLiteral, - convertedValue - ) - } - } + + convertUnaryPlusMinusCallOnIntegerLiteralIfNecessary(expression, receiver, operationToken)?.let { return it } + buildFunctionCall { source = expression.toFirSourceElement() calleeReference = buildSimpleNamedReference { diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt index a8fe4fc7fac..686bdffce00 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt @@ -32,8 +32,7 @@ import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl -import org.jetbrains.kotlin.lexer.KtTokens.CLOSING_QUOTE -import org.jetbrains.kotlin.lexer.KtTokens.OPEN_QUOTE +import org.jetbrains.kotlin.lexer.KtTokens.* import org.jetbrains.kotlin.name.CallableId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name @@ -409,6 +408,29 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte } } + fun convertUnaryPlusMinusCallOnIntegerLiteralIfNecessary( + source: T, + receiver: FirExpression, + operationToken: IElementType + ): FirExpression? { + if (receiver !is FirConstExpression<*>) return null + if (receiver.kind != ConstantValueKind.IntegerLiteral) return null + if (operationToken != PLUS && operationToken != MINUS) return null + + val value = receiver.value as Long + val convertedValue = when (operationToken) { + MINUS -> -value + PLUS -> value + else -> error("Should not be here") + } + + return buildConstExpression( + source.toFirSourceElement(), + ConstantValueKind.IntegerLiteral, + convertedValue + ) + } + fun Array.toInterpolatingCall( base: T, getElementType: (T) -> IElementType = { it.elementType },