diff --git a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt index 55be10587aa..99c8abaa73f 100644 --- a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt +++ b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt @@ -279,6 +279,7 @@ internal fun Array.toInterpolatingCall( val sb = StringBuilder() var hasExpressions = false var result: FirExpression? = null + var callCreated = false for (entry in this) { val nextArgument = when (entry) { is KtLiteralStringTemplateEntry -> { @@ -301,13 +302,19 @@ internal fun Array.toInterpolatingCall( ) } } - result = when (result) { - null -> nextArgument - else -> FirFunctionCallImpl(session, base).apply { - calleeReference = FirSimpleNamedReference(session, base, OperatorNameConventions.PLUS) - explicitReceiver = result + result = when { + result == null -> nextArgument + callCreated && result is FirFunctionCallImpl -> result.apply { arguments += nextArgument } + else -> { + callCreated = true + FirFunctionCallImpl(session, base).apply { + calleeReference = FirSimpleNamedReference(session, base, OperatorNameConventions.PLUS) + explicitReceiver = result + arguments += nextArgument + } + } } } return if (hasExpressions) result!! else FirConstExpressionImpl(session, base, IrConstKind.String, sb.toString()) diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/for.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/for.txt index 77f560d9fe3..f5024313c61 100644 --- a/compiler/fir/psi2fir/testData/rawBuilder/expressions/for.txt +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/for.txt @@ -41,7 +41,7 @@ FILE: for.kt lval : = #.next#() lval x: = #.component1() lval y: = #.component2() - println#(String(x = ).plus#(x#).plus#(String( y = )).plus#(y#)) + println#(String(x = ).plus#(x#, String( y = ), y#)) } } diff --git a/compiler/testData/ir/irText/expressions/kt28006.fir.txt b/compiler/testData/ir/irText/expressions/kt28006.fir.txt index 1045b22722c..d86238024c9 100644 --- a/compiler/testData/ir/irText/expressions/kt28006.fir.txt +++ b/compiler/testData/ir/irText/expressions/kt28006.fir.txt @@ -38,8 +38,9 @@ FILE fqName: fileName:/kt28006.kt PROPERTY name:testConst3 visibility:public modality:FINAL [const,val] FIELD PROPERTY_BACKING_FIELD name:testConst3 type:kotlin.String visibility:public [final,static] EXPRESSION_BODY - CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=null - other: CALL 'public final fun (): kotlin.String declared in ' type=kotlin.String origin=null + ERROR_CALL 'Cannot bind 2 arguments to plus call with 1 parameters' type=kotlin.String + CONST String type=kotlin.String value="\uDD17" + CALL 'public final fun (): kotlin.String declared in ' type=kotlin.String origin=null FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.String correspondingProperty: PROPERTY name:testConst3 visibility:public modality:FINAL [const,val] BLOCK_BODY @@ -59,17 +60,21 @@ FILE fqName: fileName:/kt28006.kt VALUE_PARAMETER name:x index:0 type:kotlin.Int BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test1 (x: kotlin.Int): kotlin.String declared in ' - CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=null - other: GET_VAR 'x: kotlin.Int declared in .test1' type=kotlin.Int origin=null - FUN name:test2 visibility:public modality:FINAL <> (x:kotlin.Int) returnType:kotlin.String + ERROR_CALL 'Cannot bind 2 arguments to plus call with 1 parameters' type=kotlin.String + CONST String type=kotlin.String value="\uDD17" + GET_VAR 'x: kotlin.Int declared in .test1' type=kotlin.Int origin=null + FUN name:test2 visibility:public modality:FINAL <> (x:kotlin.Int) returnType:IrErrorType VALUE_PARAMETER name:x index:0 type:kotlin.Int BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test2 (x: kotlin.Int): kotlin.String declared in ' - CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin' type=kotlin.String origin=null - other: CONST String type=kotlin.String value="\uDD17" - FUN name:test3 visibility:public modality:FINAL <> (x:kotlin.Int) returnType:kotlin.String + RETURN type=kotlin.Nothing from='public final fun test2 (x: kotlin.Int): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + CONST String type=kotlin.String value="\uD83E" + CONST String type=kotlin.String value="\uDD17" + FUN name:test3 visibility:public modality:FINAL <> (x:kotlin.Int) returnType:IrErrorType VALUE_PARAMETER name:x index:0 type:kotlin.Int BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test3 (x: kotlin.Int): kotlin.String declared in ' - CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=null - other: GET_VAR 'x: kotlin.Int declared in .test3' type=kotlin.Int origin=null + RETURN type=kotlin.Nothing from='public final fun test3 (x: kotlin.Int): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + CONST String type=kotlin.String value="\uD83E" + CONST String type=kotlin.String value="\uDD17" + GET_VAR 'x: kotlin.Int declared in .test3' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/expressions/stringTemplates.fir.txt b/compiler/testData/ir/irText/expressions/stringTemplates.fir.txt index c9a6a540f83..32232ba4d89 100644 --- a/compiler/testData/ir/irText/expressions/stringTemplates.fir.txt +++ b/compiler/testData/ir/irText/expressions/stringTemplates.fir.txt @@ -60,8 +60,9 @@ FILE fqName: fileName:/stringTemplates.kt PROPERTY name:test6 visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:test6 type:kotlin.String visibility:public [final,static] EXPRESSION_BODY - CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=null - other: CALL 'public final fun foo (): kotlin.String declared in ' type=kotlin.String origin=null + ERROR_CALL 'Cannot bind 2 arguments to plus call with 1 parameters' type=kotlin.String + CONST String type=kotlin.String value=" " + CALL 'public final fun foo (): kotlin.String declared in ' type=kotlin.String origin=null FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.String correspondingProperty: PROPERTY name:test6 visibility:public modality:FINAL [val] BLOCK_BODY