Raw FIR: add work-around for deeply nested String interpolations
Controversial (but prevents total kotlin test failing) Related to KT-29222
This commit is contained in:
@@ -279,6 +279,7 @@ internal fun Array<KtStringTemplateEntry>.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<KtStringTemplateEntry>.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())
|
||||
|
||||
@@ -41,7 +41,7 @@ FILE: for.kt
|
||||
lval <destruct>: <implicit> = <iterator>#.next#()
|
||||
lval x: <implicit> = <destruct>#.component1()
|
||||
lval y: <implicit> = <destruct>#.component2()
|
||||
println#(String(x = ).plus#(x#).plus#(String( y = )).plus#(y#))
|
||||
println#(String(x = ).plus#(x#, String( y = ), y#))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user