Clarify comments about KT-36625 that it is pending design decision.

This commit is contained in:
Mark Punzalan
2020-02-12 11:51:30 -08:00
committed by Dmitry Petrov
parent ba606147c9
commit 89cf32eccc
2 changed files with 7 additions and 6 deletions
@@ -114,10 +114,10 @@ private class JvmStringConcatenationLowering(val context: JvmBackendContext) : F
override fun visitStringConcatenation(expression: IrStringConcatenation): IrExpression {
expression.transformChildrenVoid(this)
return context.createJvmIrBuilder(currentScope!!.scope.scopeOwnerSymbol, expression.startOffset, expression.endOffset).run {
// When `String.plus(Any?)` is invoked with receiver of platform type String or String with enhanced nullability, this SHOULD
// fail a nullability check (NullPointerException) on the receiver. However, the non-IR backend has a bug (KT-36625) where this
// check is not inserted (see KT-36625). To maintain bug compatibility with the non-IR backend, we remove IMPLICIT_NOTNULL casts
// (which generate the nullability checks in JvmArgumentNullabilityAssertionsLowering) from all arguments.
// When `String.plus(Any?)` is invoked with receiver of platform type String or String with enhanced nullability, this could
// fail a nullability check (NullPointerException) on the receiver. However, the non-IR backend currently does NOT insert this
// check (see KT-36625, pending language design decision). To maintain compatibility with the non-IR backend, we remove
// IMPLICIT_NOTNULL casts from all arguments (nullability checks are generated in JvmArgumentNullabilityAssertionsLowering).
fun IrExpression.unwrapImplicitNotNull() =
if (this is IrTypeOperatorCall && operator == IrTypeOperator.IMPLICIT_NOTNULL)
@@ -36,13 +36,14 @@ public class J {
}
}
// FILE: main.kt
// FILE: stringFromJavaPlus.kt
import kotlin.test.assertEquals
fun box(): String {
val n = 123
// Due to KT-36625, certain concatenation calls below (marked with a comment) SHOULD fail a nullability check but do not.
// Null check behavior in string concatenation might change depending on language design decision for KT-36625.
// Cases below that could be affected by KT-36625 are marked with a comment.
assertEquals("null", "${J.platformStringIsNull()}")
assertEquals("nullBAR", J.platformStringIsNull() + "BAR") // KT-36625