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:
Mikhail Glukhikh
2019-04-05 15:32:56 +03:00
parent 881073b1c9
commit ee28467a47
4 changed files with 33 additions and 20 deletions
@@ -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#))
}
}
+17 -12
View File
@@ -38,8 +38,9 @@ FILE fqName:<root> 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 <get-testConst2> (): kotlin.String declared in <root>' 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 <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
correspondingProperty: PROPERTY name:testConst3 visibility:public modality:FINAL [const,val]
BLOCK_BODY
@@ -59,17 +60,21 @@ FILE fqName:<root> 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 <root>'
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 <root>.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 <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
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test2 (x: kotlin.Int): kotlin.String declared in <root>'
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 <root>'
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
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 <root>'
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 <root>.test3' type=kotlin.Int origin=null
RETURN type=kotlin.Nothing from='public final fun test3 (x: kotlin.Int): IrErrorType declared in <root>'
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
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]
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 <root>' 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 <root>' type=kotlin.String origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test6> visibility:public modality:FINAL <> () returnType:kotlin.String
correspondingProperty: PROPERTY name:test6 visibility:public modality:FINAL [val]
BLOCK_BODY