From 89cf32eccc813b10b506799ae132f1fb5dbf03a9 Mon Sep 17 00:00:00 2001 From: Mark Punzalan Date: Wed, 12 Feb 2020 11:51:30 -0800 Subject: [PATCH] Clarify comments about KT-36625 that it is pending design decision. --- .../backend/jvm/lower/JvmStringConcatenationLowering.kt | 8 ++++---- .../testData/codegen/box/strings/stringFromJavaPlus.kt | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStringConcatenationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStringConcatenationLowering.kt index 1d741448a00..1ae906bcbe3 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStringConcatenationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStringConcatenationLowering.kt @@ -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) diff --git a/compiler/testData/codegen/box/strings/stringFromJavaPlus.kt b/compiler/testData/codegen/box/strings/stringFromJavaPlus.kt index 5adf2e220bd..94a6a0a5051 100644 --- a/compiler/testData/codegen/box/strings/stringFromJavaPlus.kt +++ b/compiler/testData/codegen/box/strings/stringFromJavaPlus.kt @@ -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