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()
|
val sb = StringBuilder()
|
||||||
var hasExpressions = false
|
var hasExpressions = false
|
||||||
var result: FirExpression? = null
|
var result: FirExpression? = null
|
||||||
|
var callCreated = false
|
||||||
for (entry in this) {
|
for (entry in this) {
|
||||||
val nextArgument = when (entry) {
|
val nextArgument = when (entry) {
|
||||||
is KtLiteralStringTemplateEntry -> {
|
is KtLiteralStringTemplateEntry -> {
|
||||||
@@ -301,13 +302,19 @@ internal fun Array<KtStringTemplateEntry>.toInterpolatingCall(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = when (result) {
|
result = when {
|
||||||
null -> nextArgument
|
result == null -> nextArgument
|
||||||
else -> FirFunctionCallImpl(session, base).apply {
|
callCreated && result is FirFunctionCallImpl -> result.apply {
|
||||||
calleeReference = FirSimpleNamedReference(session, base, OperatorNameConventions.PLUS)
|
|
||||||
explicitReceiver = result
|
|
||||||
arguments += nextArgument
|
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())
|
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 <destruct>: <implicit> = <iterator>#.next#()
|
||||||
lval x: <implicit> = <destruct>#.component1()
|
lval x: <implicit> = <destruct>#.component1()
|
||||||
lval y: <implicit> = <destruct>#.component2()
|
lval y: <implicit> = <destruct>#.component2()
|
||||||
println#(String(x = ).plus#(x#).plus#(String( y = )).plus#(y#))
|
println#(String(x = ).plus#(x#, String( y = ), y#))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-12
@@ -38,8 +38,9 @@ FILE fqName:<root> fileName:/kt28006.kt
|
|||||||
PROPERTY name:testConst3 visibility:public modality:FINAL [const,val]
|
PROPERTY name:testConst3 visibility:public modality:FINAL [const,val]
|
||||||
FIELD PROPERTY_BACKING_FIELD name:testConst3 type:kotlin.String visibility:public [final,static]
|
FIELD PROPERTY_BACKING_FIELD name:testConst3 type:kotlin.String visibility:public [final,static]
|
||||||
EXPRESSION_BODY
|
EXPRESSION_BODY
|
||||||
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=null
|
ERROR_CALL 'Cannot bind 2 arguments to plus call with 1 parameters' type=kotlin.String
|
||||||
other: CALL 'public final fun <get-testConst2> (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
CONST String type=kotlin.String value="\uDD17"
|
||||||
|
CALL 'public final fun <get-testConst2> (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
||||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-testConst3> visibility:public modality:FINAL <> () returnType:kotlin.String
|
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-testConst3> visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||||
correspondingProperty: PROPERTY name:testConst3 visibility:public modality:FINAL [const,val]
|
correspondingProperty: PROPERTY name:testConst3 visibility:public modality:FINAL [const,val]
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
@@ -59,17 +60,21 @@ FILE fqName:<root> fileName:/kt28006.kt
|
|||||||
VALUE_PARAMETER name:x index:0 type:kotlin.Int
|
VALUE_PARAMETER name:x index:0 type:kotlin.Int
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
RETURN type=kotlin.Nothing from='public final fun test1 (x: kotlin.Int): kotlin.String declared in <root>'
|
RETURN type=kotlin.Nothing from='public final fun test1 (x: kotlin.Int): kotlin.String declared in <root>'
|
||||||
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=null
|
ERROR_CALL 'Cannot bind 2 arguments to plus call with 1 parameters' type=kotlin.String
|
||||||
other: GET_VAR 'x: kotlin.Int declared in <root>.test1' type=kotlin.Int origin=null
|
CONST String type=kotlin.String value="\uDD17"
|
||||||
FUN name:test2 visibility:public modality:FINAL <> (x:kotlin.Int) returnType:kotlin.String
|
GET_VAR 'x: kotlin.Int declared in <root>.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
|
VALUE_PARAMETER name:x index:0 type:kotlin.Int
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
RETURN type=kotlin.Nothing from='public final fun test2 (x: kotlin.Int): kotlin.String declared in <root>'
|
RETURN type=kotlin.Nothing from='public final fun test2 (x: kotlin.Int): IrErrorType declared in <root>'
|
||||||
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin' type=kotlin.String origin=null
|
ERROR_CALL 'Unresolved reference: <Ambiguity: plus, [kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus]>#' type=IrErrorType
|
||||||
other: CONST String type=kotlin.String value="\uDD17"
|
CONST String type=kotlin.String value="\uD83E"
|
||||||
FUN name:test3 visibility:public modality:FINAL <> (x:kotlin.Int) returnType:kotlin.String
|
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
|
VALUE_PARAMETER name:x index:0 type:kotlin.Int
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
RETURN type=kotlin.Nothing from='public final fun test3 (x: kotlin.Int): kotlin.String declared in <root>'
|
RETURN type=kotlin.Nothing from='public final fun test3 (x: kotlin.Int): IrErrorType declared in <root>'
|
||||||
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=null
|
ERROR_CALL 'Unresolved reference: <Ambiguity: plus, [kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus]>#' type=IrErrorType
|
||||||
other: GET_VAR 'x: kotlin.Int declared in <root>.test3' type=kotlin.Int origin=null
|
CONST String type=kotlin.String value="\uD83E"
|
||||||
|
CONST String type=kotlin.String value="\uDD17"
|
||||||
|
GET_VAR 'x: kotlin.Int declared in <root>.test3' type=kotlin.Int origin=null
|
||||||
|
|||||||
@@ -60,8 +60,9 @@ FILE fqName:<root> fileName:/stringTemplates.kt
|
|||||||
PROPERTY name:test6 visibility:public modality:FINAL [val]
|
PROPERTY name:test6 visibility:public modality:FINAL [val]
|
||||||
FIELD PROPERTY_BACKING_FIELD name:test6 type:kotlin.String visibility:public [final,static]
|
FIELD PROPERTY_BACKING_FIELD name:test6 type:kotlin.String visibility:public [final,static]
|
||||||
EXPRESSION_BODY
|
EXPRESSION_BODY
|
||||||
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=null
|
ERROR_CALL 'Cannot bind 2 arguments to plus call with 1 parameters' type=kotlin.String
|
||||||
other: CALL 'public final fun foo (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
CONST String type=kotlin.String value=" "
|
||||||
|
CALL 'public final fun foo (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
||||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test6> visibility:public modality:FINAL <> () returnType:kotlin.String
|
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test6> visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||||
correspondingProperty: PROPERTY name:test6 visibility:public modality:FINAL [val]
|
correspondingProperty: PROPERTY name:test6 visibility:public modality:FINAL [val]
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
|
|||||||
Reference in New Issue
Block a user