From fc0ce415d71ba8ac452865507208f69b8090fdaa Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 25 Apr 2023 00:59:52 +0200 Subject: [PATCH] JVM: remove source code from not null assertion message text This is implemented under a LanguageFeature which will be enabled later, when behavior change described in KT-57570 is approved. #KT-57570 --- .../kotlin/codegen/state/GenerationState.kt | 14 +++- ...LightTreeBlackBoxCodegenTestGenerated.java | 82 ++++++++++++++++--- .../FirPsiBlackBoxCodegenTestGenerated.java | 82 ++++++++++++++++--- .../backend/jvm/lower/TypeOperatorLowering.kt | 52 ++++++++---- .../field_after.kt | 21 +++++ .../field_before.kt | 22 +++++ .../localVariable_after.kt | 22 +++++ .../localVariable_before.kt | 23 ++++++ .../simple_after.kt | 21 +++++ .../simple_before.kt} | 1 + .../staticCall_after.kt | 21 +++++ .../staticCall_before.kt} | 1 + .../syntheticProperty_after.kt | 21 +++++ .../syntheticProperty_before.kt | 22 +++++ .../codegen/BlackBoxCodegenTestGenerated.java | 82 ++++++++++++++++--- .../IrBlackBoxCodegenTestGenerated.java | 82 ++++++++++++++++--- ...kBoxCodegenWithIrInlinerTestGenerated.java | 82 ++++++++++++++++--- .../LightAnalysisModeTestGenerated.java | 73 ++++++++++++++--- .../kotlin/config/LanguageVersionSettings.kt | 1 + .../js/test/JsCodegenBoxTestGenerated.java | 10 +++ .../fir/FirJsCodegenBoxTestGenerated.java | 10 +++ .../test/ir/IrJsCodegenBoxTestGenerated.java | 10 +++ .../ir/IrJsES6CodegenBoxTestGenerated.java | 10 +++ .../FirNativeCodegenBoxTestGenerated.java | 14 ++++ .../FirNativeCodegenBoxTestNoPLGenerated.java | 16 ++++ .../NativeCodegenBoxTestGenerated.java | 13 +++ .../NativeCodegenBoxTestNoPLGenerated.java | 15 ++++ .../test/IrCodegenBoxWasmTestGenerated.java | 13 +++ 28 files changed, 746 insertions(+), 90 deletions(-) create mode 100644 compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_after.kt create mode 100644 compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_before.kt create mode 100644 compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_after.kt create mode 100644 compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_before.kt create mode 100644 compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_after.kt rename compiler/testData/codegen/box/javaInterop/notNullAssertions/{errorMessage.kt => expressionAssertionMessages/simple_before.kt} (88%) create mode 100644 compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_after.kt rename compiler/testData/codegen/box/javaInterop/notNullAssertions/{staticCallErrorMessage.kt => expressionAssertionMessages/staticCall_before.kt} (89%) create mode 100644 compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_after.kt create mode 100644 compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_before.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt index 4863bd754cc..ed8edde8dc0 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt @@ -320,9 +320,17 @@ class GenerationState private constructor( val assertionsMode: JVMAssertionsMode = configuration.get(JVMConfigurationKeys.ASSERTIONS_MODE, JVMAssertionsMode.DEFAULT) val isInlineDisabled: Boolean = configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE) val useTypeTableInSerializer: Boolean = configuration.getBoolean(JVMConfigurationKeys.USE_TYPE_TABLE) - val unifiedNullChecks: Boolean = - languageVersionSettings.apiVersion >= ApiVersion.KOTLIN_1_4 && - !configuration.getBoolean(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS) + val unifiedNullChecks: Boolean = ( + languageVersionSettings.apiVersion >= ApiVersion.KOTLIN_1_4 && + !configuration.getBoolean(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS) + ).also { + check(it || !languageVersionSettings.supportsFeature(LanguageFeature.NoSourceCodeInNotNullAssertionExceptions)) { + // This assertion is needed because we generate calls to `Intrinsics.checkNotNull` which is only available since 1.4. + "Language feature ${LanguageFeature.NoSourceCodeInNotNullAssertionExceptions.name} is not supported " + + "if -Xno-unified-null-checks is enabled." + } + } + val generateSmapCopyToAnnotation: Boolean = !configuration.getBoolean(JVMConfigurationKeys.NO_SOURCE_DEBUG_EXTENSION) val functionsWithInlineClassReturnTypesMangled: Boolean = languageVersionSettings.supportsFeature(LanguageFeature.MangleClassMembersReturningInlineClasses) diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index 35f65fd7c8d..031d9ca1149 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -29182,12 +29182,6 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/destructuringAssignmentWithNullabilityAssertionOnExtensionReceiver_lv12.kt"); } - @Test - @TestMetadata("errorMessage.kt") - public void testErrorMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt"); - } - @Test @TestMetadata("extensionReceiverParameter.kt") public void testExtensionReceiverParameter() throws Exception { @@ -29296,12 +29290,6 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/privateOperatorParameterAssertions.kt"); } - @Test - @TestMetadata("staticCallErrorMessage.kt") - public void testStaticCallErrorMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt"); - } - @Test @TestMetadata("typeParameterWithMixedNullableAndNotNullableBounds.kt") public void testTypeParameterWithMixedNullableAndNotNullableBounds() throws Exception { @@ -29378,6 +29366,76 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("field_after.kt") + public void testField_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_after.kt"); + } + + @Test + @TestMetadata("field_before.kt") + public void testField_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_before.kt"); + } + + @Test + @TestMetadata("localVariable_after.kt") + public void testLocalVariable_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_after.kt"); + } + + @Test + @TestMetadata("localVariable_before.kt") + public void testLocalVariable_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_before.kt"); + } + + @Test + @TestMetadata("simple_after.kt") + public void testSimple_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_after.kt"); + } + + @Test + @TestMetadata("simple_before.kt") + public void testSimple_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_before.kt"); + } + + @Test + @TestMetadata("staticCall_after.kt") + public void testStaticCall_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_after.kt"); + } + + @Test + @TestMetadata("staticCall_before.kt") + public void testStaticCall_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_before.kt"); + } + + @Test + @TestMetadata("syntheticProperty_after.kt") + public void testSyntheticProperty_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_after.kt"); + } + + @Test + @TestMetadata("syntheticProperty_before.kt") + public void testSyntheticProperty_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_before.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index 1c987fc8032..ad59a10e1c4 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -29182,12 +29182,6 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/destructuringAssignmentWithNullabilityAssertionOnExtensionReceiver_lv12.kt"); } - @Test - @TestMetadata("errorMessage.kt") - public void testErrorMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt"); - } - @Test @TestMetadata("extensionReceiverParameter.kt") public void testExtensionReceiverParameter() throws Exception { @@ -29296,12 +29290,6 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/privateOperatorParameterAssertions.kt"); } - @Test - @TestMetadata("staticCallErrorMessage.kt") - public void testStaticCallErrorMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt"); - } - @Test @TestMetadata("typeParameterWithMixedNullableAndNotNullableBounds.kt") public void testTypeParameterWithMixedNullableAndNotNullableBounds() throws Exception { @@ -29378,6 +29366,76 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("field_after.kt") + public void testField_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_after.kt"); + } + + @Test + @TestMetadata("field_before.kt") + public void testField_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_before.kt"); + } + + @Test + @TestMetadata("localVariable_after.kt") + public void testLocalVariable_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_after.kt"); + } + + @Test + @TestMetadata("localVariable_before.kt") + public void testLocalVariable_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_before.kt"); + } + + @Test + @TestMetadata("simple_after.kt") + public void testSimple_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_after.kt"); + } + + @Test + @TestMetadata("simple_before.kt") + public void testSimple_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_before.kt"); + } + + @Test + @TestMetadata("staticCall_after.kt") + public void testStaticCall_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_after.kt"); + } + + @Test + @TestMetadata("staticCall_before.kt") + public void testStaticCall_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_before.kt"); + } + + @Test + @TestMetadata("syntheticProperty_after.kt") + public void testSyntheticProperty_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_after.kt"); + } + + @Test + @TestMetadata("syntheticProperty_before.kt") + public void testSyntheticProperty_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_before.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt index a7d85776ea6..bc5950449c9 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin import org.jetbrains.kotlin.backend.jvm.ir.* import org.jetbrains.kotlin.backend.jvm.unboxInlineClass +import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement @@ -736,26 +737,19 @@ private class TypeOperatorLowering(private val backendContext: JvmBackendContext irNot(lowerInstanceOf(expression.argument.transformVoid(), expression.typeOperand)) IrTypeOperator.IMPLICIT_NOTNULL -> { - val owner = scope.scopeOwnerSymbol.owner - val source = if (owner is IrFunction && owner.isDelegated()) { - "${owner.name.asString()}(...)" - } else { - val declarationParent = parent as? IrDeclaration - val sourceView = declarationParent?.let(::sourceViewFor) - val (startOffset, endOffset) = expression.extents() - if (sourceView?.validSourcePosition(startOffset, endOffset) == true) { - sourceView.subSequence(startOffset, endOffset).toString() - } else { - // Fallback for inconsistent line numbers - (declarationParent as? IrDeclarationWithName)?.name?.asString() ?: "Unknown Declaration" - } - } + val text = computeNotNullAssertionText(expression) irLetS(expression.argument.transformVoid(), irType = context.irBuiltIns.anyNType) { valueSymbol -> irComposite(resultType = expression.type) { - +irCall(checkExpressionValueIsNotNull).apply { - putValueArgument(0, irGet(valueSymbol.owner)) - putValueArgument(1, irString(source.trimForRuntimeAssertion())) + if (text != null) { + +irCall(checkExpressionValueIsNotNull).apply { + putValueArgument(0, irGet(valueSymbol.owner)) + putValueArgument(1, irString(text.trimForRuntimeAssertion())) + } + } else { + +irCall(backendContext.ir.symbols.checkNotNull).apply { + putValueArgument(0, irGet(valueSymbol.owner)) + } } +irGet(valueSymbol.owner) } @@ -769,6 +763,30 @@ private class TypeOperatorLowering(private val backendContext: JvmBackendContext } } + private fun IrBuilderWithScope.computeNotNullAssertionText(typeOperatorCall: IrTypeOperatorCall): String? { + if (backendContext.state.languageVersionSettings.supportsFeature(LanguageFeature.NoSourceCodeInNotNullAssertionExceptions)) { + return when (val argument = typeOperatorCall.argument) { + is IrCall -> "${argument.symbol.owner.name.asString()}(...)" + is IrGetField -> argument.symbol.owner.name.asString() + else -> null + } + } + + val owner = scope.scopeOwnerSymbol.owner + if (owner is IrFunction && owner.isDelegated()) + return "${owner.name.asString()}(...)" + + val declarationParent = parent as? IrDeclaration + val sourceView = declarationParent?.let(::sourceViewFor) + val (startOffset, endOffset) = typeOperatorCall.extents() + return if (sourceView?.validSourcePosition(startOffset, endOffset) == true) { + sourceView.subSequence(startOffset, endOffset).toString() + } else { + // Fallback for inconsistent line numbers + (declarationParent as? IrDeclarationWithName)?.name?.asString() ?: "Unknown Declaration" + } + } + private fun String.trimForRuntimeAssertion() = StringUtil.trimMiddle(this, 50) private fun IrFunction.isDelegated() = diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_after.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_after.kt new file mode 100644 index 00000000000..a2492908e96 --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_after.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +NoSourceCodeInNotNullAssertionExceptions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// FILE: test.kt +fun f(x: String) = "Fail 1" + +fun box(): String { + return try { + f(J().s) + } catch (e: NullPointerException) { + if (e.message == "s must not be null") + "OK" + else + "Fail: ${e.message}" + } +} + +// FILE: J.java +public class J { + public String s = null; +} diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_before.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_before.kt new file mode 100644 index 00000000000..4701eefd2bd --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_before.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: -NoSourceCodeInNotNullAssertionExceptions +// IGNORE_BACKEND_K2_LIGHT_TREE: JVM_IR +// Reason: KT-56760 +// TARGET_BACKEND: JVM +// FILE: test.kt +fun f(x: String) = "Fail 1" + +fun box(): String { + return try { + f(J().s) + } catch (e: NullPointerException) { + if (e.message == "J().s must not be null") + "OK" + else + "Fail: ${e.message}" + } +} + +// FILE: J.java +public class J { + public String s = null; +} diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_after.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_after.kt new file mode 100644 index 00000000000..d20f254101e --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_after.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +NoSourceCodeInNotNullAssertionExceptions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// FILE: test.kt +fun f(x: String) = "Fail 1" + +fun box(): String { + return try { + val variable = J().s() + f(variable) + } catch (e: NullPointerException) { + if (e.message == null) + "OK" + else + "Fail: ${e.message}" + } +} + +// FILE: J.java +public class J { + public final String s() { return null; } +} diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_before.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_before.kt new file mode 100644 index 00000000000..e62d0192375 --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_before.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: -NoSourceCodeInNotNullAssertionExceptions +// IGNORE_BACKEND_K2_LIGHT_TREE: JVM_IR +// Reason: KT-56760 +// TARGET_BACKEND: JVM +// FILE: test.kt +fun f(x: String) = "Fail 1" + +fun box(): String { + return try { + val variable = J().s() + f(variable) + } catch (e: NullPointerException) { + if (e.message == "variable must not be null") + "OK" + else + "Fail: ${e.message}" + } +} + +// FILE: J.java +public class J { + public final String s() { return null; } +} diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_after.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_after.kt new file mode 100644 index 00000000000..b8fe01bc9e6 --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_after.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +NoSourceCodeInNotNullAssertionExceptions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// FILE: test.kt +fun f(x: String) = "Fail 1" + +fun box(): String { + return try { + f(J().s()) + } catch (e: NullPointerException) { + if (e.message == "s(...) must not be null") + "OK" + else + "Fail: ${e.message}" + } +} + +// FILE: J.java +public class J { + public final String s() { return null; } +} diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_before.kt similarity index 88% rename from compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt rename to compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_before.kt index e73d15436b7..cc42333f13a 100644 --- a/compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_before.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: -NoSourceCodeInNotNullAssertionExceptions // IGNORE_BACKEND_K2_LIGHT_TREE: JVM_IR // Reason: KT-56760 // TARGET_BACKEND: JVM diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_after.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_after.kt new file mode 100644 index 00000000000..c7f30e0feef --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_after.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +NoSourceCodeInNotNullAssertionExceptions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// FILE: test.kt +fun f(x: String) = "Fail 1" + +fun box(): String { + return try { + f(J.s()) + } catch (e: NullPointerException) { + if (e.message == "s(...) must not be null") + "OK" + else + "Fail: ${e.message}" + } +} + +// FILE: J.java +public class J { + public static String s() { return null; } +} diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_before.kt similarity index 89% rename from compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt rename to compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_before.kt index f27a8d66db0..42ced26a895 100644 --- a/compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_before.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: -NoSourceCodeInNotNullAssertionExceptions // IGNORE_BACKEND_K2_LIGHT_TREE: JVM_IR // Reason: KT-56760 // TARGET_BACKEND: JVM diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_after.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_after.kt new file mode 100644 index 00000000000..76d9061aa46 --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_after.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +NoSourceCodeInNotNullAssertionExceptions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// FILE: test.kt +fun f(x: String) = "Fail 1" + +fun box(): String { + return try { + f(J().s) + } catch (e: NullPointerException) { + if (e.message == "getS(...) must not be null") + "OK" + else + "Fail: ${e.message}" + } +} + +// FILE: J.java +public class J { + public String getS() { return null; } +} diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_before.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_before.kt new file mode 100644 index 00000000000..95f31431e6c --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_before.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: -NoSourceCodeInNotNullAssertionExceptions +// IGNORE_BACKEND_K2_LIGHT_TREE: JVM_IR +// Reason: KT-56760 +// TARGET_BACKEND: JVM +// FILE: test.kt +fun f(x: String) = "Fail 1" + +fun box(): String { + return try { + f(J().s) + } catch (e: NullPointerException) { + if (e.message == "J().s must not be null") + "OK" + else + "Fail: ${e.message}" + } +} + +// FILE: J.java +public class J { + public String getS() { return null; } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index b7c523dd23f..d276ab5525b 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -27766,12 +27766,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/destructuringAssignmentWithNullabilityAssertionOnExtensionReceiver_lv12.kt"); } - @Test - @TestMetadata("errorMessage.kt") - public void testErrorMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt"); - } - @Test @TestMetadata("extensionReceiverParameter.kt") public void testExtensionReceiverParameter() throws Exception { @@ -27880,12 +27874,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/privateOperatorParameterAssertions.kt"); } - @Test - @TestMetadata("staticCallErrorMessage.kt") - public void testStaticCallErrorMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt"); - } - @Test @TestMetadata("typeParameterWithMixedNullableAndNotNullableBounds.kt") public void testTypeParameterWithMixedNullableAndNotNullableBounds() throws Exception { @@ -27962,6 +27950,76 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @Test + @TestMetadata("field_after.kt") + public void testField_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_after.kt"); + } + + @Test + @TestMetadata("field_before.kt") + public void testField_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_before.kt"); + } + + @Test + @TestMetadata("localVariable_after.kt") + public void testLocalVariable_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_after.kt"); + } + + @Test + @TestMetadata("localVariable_before.kt") + public void testLocalVariable_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_before.kt"); + } + + @Test + @TestMetadata("simple_after.kt") + public void testSimple_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_after.kt"); + } + + @Test + @TestMetadata("simple_before.kt") + public void testSimple_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_before.kt"); + } + + @Test + @TestMetadata("staticCall_after.kt") + public void testStaticCall_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_after.kt"); + } + + @Test + @TestMetadata("staticCall_before.kt") + public void testStaticCall_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_before.kt"); + } + + @Test + @TestMetadata("syntheticProperty_after.kt") + public void testSyntheticProperty_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_after.kt"); + } + + @Test + @TestMetadata("syntheticProperty_before.kt") + public void testSyntheticProperty_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_before.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index d83dc25b832..602152bdfbc 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -29182,12 +29182,6 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/destructuringAssignmentWithNullabilityAssertionOnExtensionReceiver_lv12.kt"); } - @Test - @TestMetadata("errorMessage.kt") - public void testErrorMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt"); - } - @Test @TestMetadata("extensionReceiverParameter.kt") public void testExtensionReceiverParameter() throws Exception { @@ -29296,12 +29290,6 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/privateOperatorParameterAssertions.kt"); } - @Test - @TestMetadata("staticCallErrorMessage.kt") - public void testStaticCallErrorMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt"); - } - @Test @TestMetadata("typeParameterWithMixedNullableAndNotNullableBounds.kt") public void testTypeParameterWithMixedNullableAndNotNullableBounds() throws Exception { @@ -29378,6 +29366,76 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("field_after.kt") + public void testField_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_after.kt"); + } + + @Test + @TestMetadata("field_before.kt") + public void testField_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_before.kt"); + } + + @Test + @TestMetadata("localVariable_after.kt") + public void testLocalVariable_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_after.kt"); + } + + @Test + @TestMetadata("localVariable_before.kt") + public void testLocalVariable_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_before.kt"); + } + + @Test + @TestMetadata("simple_after.kt") + public void testSimple_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_after.kt"); + } + + @Test + @TestMetadata("simple_before.kt") + public void testSimple_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_before.kt"); + } + + @Test + @TestMetadata("staticCall_after.kt") + public void testStaticCall_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_after.kt"); + } + + @Test + @TestMetadata("staticCall_before.kt") + public void testStaticCall_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_before.kt"); + } + + @Test + @TestMetadata("syntheticProperty_after.kt") + public void testSyntheticProperty_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_after.kt"); + } + + @Test + @TestMetadata("syntheticProperty_before.kt") + public void testSyntheticProperty_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_before.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index 9da33147b1f..22c0e785450 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -29182,12 +29182,6 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/destructuringAssignmentWithNullabilityAssertionOnExtensionReceiver_lv12.kt"); } - @Test - @TestMetadata("errorMessage.kt") - public void testErrorMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt"); - } - @Test @TestMetadata("extensionReceiverParameter.kt") public void testExtensionReceiverParameter() throws Exception { @@ -29296,12 +29290,6 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/privateOperatorParameterAssertions.kt"); } - @Test - @TestMetadata("staticCallErrorMessage.kt") - public void testStaticCallErrorMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt"); - } - @Test @TestMetadata("typeParameterWithMixedNullableAndNotNullableBounds.kt") public void testTypeParameterWithMixedNullableAndNotNullableBounds() throws Exception { @@ -29378,6 +29366,76 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("field_after.kt") + public void testField_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_after.kt"); + } + + @Test + @TestMetadata("field_before.kt") + public void testField_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_before.kt"); + } + + @Test + @TestMetadata("localVariable_after.kt") + public void testLocalVariable_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_after.kt"); + } + + @Test + @TestMetadata("localVariable_before.kt") + public void testLocalVariable_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_before.kt"); + } + + @Test + @TestMetadata("simple_after.kt") + public void testSimple_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_after.kt"); + } + + @Test + @TestMetadata("simple_before.kt") + public void testSimple_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_before.kt"); + } + + @Test + @TestMetadata("staticCall_after.kt") + public void testStaticCall_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_after.kt"); + } + + @Test + @TestMetadata("staticCall_before.kt") + public void testStaticCall_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_before.kt"); + } + + @Test + @TestMetadata("syntheticProperty_after.kt") + public void testSyntheticProperty_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_after.kt"); + } + + @Test + @TestMetadata("syntheticProperty_before.kt") + public void testSyntheticProperty_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_before.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 75535208bce..8ae7c387cd1 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -23495,11 +23495,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/destructuringAssignmentWithNullabilityAssertionOnExtensionReceiver_lv12.kt"); } - @TestMetadata("errorMessage.kt") - public void testErrorMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt"); - } - @TestMetadata("extensionReceiverParameter.kt") public void testExtensionReceiverParameter() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/extensionReceiverParameter.kt"); @@ -23585,11 +23580,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/privateOperatorParameterAssertions.kt"); } - @TestMetadata("staticCallErrorMessage.kt") - public void testStaticCallErrorMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt"); - } - @TestMetadata("typeParameterWithMultipleNotNullableBounds.kt") public void testTypeParameterWithMultipleNotNullableBounds() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/typeParameterWithMultipleNotNullableBounds.kt"); @@ -23653,6 +23643,69 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ExpressionAssertionMessages extends AbstractLightAnalysisModeTest { + @TestMetadata("field_after.kt") + public void ignoreField_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_after.kt"); + } + + @TestMetadata("localVariable_after.kt") + public void ignoreLocalVariable_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_after.kt"); + } + + @TestMetadata("simple_after.kt") + public void ignoreSimple_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_after.kt"); + } + + @TestMetadata("staticCall_after.kt") + public void ignoreStaticCall_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_after.kt"); + } + + @TestMetadata("syntheticProperty_after.kt") + public void ignoreSyntheticProperty_after() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_after.kt"); + } + + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("field_before.kt") + public void testField_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/field_before.kt"); + } + + @TestMetadata("localVariable_before.kt") + public void testLocalVariable_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/localVariable_before.kt"); + } + + @TestMetadata("simple_before.kt") + public void testSimple_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/simple_before.kt"); + } + + @TestMetadata("staticCall_before.kt") + public void testStaticCall_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/staticCall_before.kt"); + } + + @TestMetadata("syntheticProperty_before.kt") + public void testSyntheticProperty_before() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/syntheticProperty_before.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 4251c9cd454..1b5917b019e 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -340,6 +340,7 @@ enum class LanguageFeature( ImplicitSignedToUnsignedIntegerConversion(sinceVersion = null), // KT-56583 ForbidInferringTypeVariablesIntoEmptyIntersection(sinceVersion = null, kind = BUG_FIX), // KT-51221 IntrinsicConstEvaluation(sinceVersion = null, kind = UNSTABLE_FEATURE), // KT-49303 + NoSourceCodeInNotNullAssertionExceptions(sinceVersion = null, sinceApiVersion = ApiVersion.KOTLIN_1_4, kind = OTHER), // KT-57570 ; init { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index 6c2c2a3a610..10cbc2b34a3 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -21560,6 +21560,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java index 7e289600733..78dbf126d65 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java @@ -21698,6 +21698,16 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest { } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 449ce5a1267..a388c356438 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -21698,6 +21698,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java index c2bc806eb66..48fde28635c 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java @@ -21698,6 +21698,16 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java index 74fcb6cc1af..99cb4ec10b6 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java @@ -24882,6 +24882,20 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + @Tag("codegenK2") + @Tag("firCodegen") + @UseExtTestCaseGroupProvider() + @FirPipeline() + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java index 7696f8990dc..07313647f8f 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java @@ -25376,6 +25376,22 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + @Tag("codegenK2") + @Tag("firCodegen") + @UseExtTestCaseGroupProvider() + @FirPipeline() + @UsePartialLinkage(mode = Mode.DISABLED) + @Tag("no-partial-linkage-may-be-skipped") + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 174cec6a718..d9c1dae7d68 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -24635,6 +24635,19 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + @Tag("codegen") + @Tag("k1Codegen") + @UseExtTestCaseGroupProvider() + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java index d91868281b7..1c58c709145 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java @@ -25129,6 +25129,21 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT } } + @Nested + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + @Tag("codegen") + @Tag("k1Codegen") + @UseExtTestCaseGroupProvider() + @UsePartialLinkage(mode = Mode.DISABLED) + @Tag("no-partial-linkage-may-be-skipped") + public class ExpressionAssertionMessages { + @Test + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") diff --git a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java index 55b2119f1e1..a72d8da0799 100644 --- a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java +++ b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java @@ -19156,6 +19156,19 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest } } + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ExpressionAssertionMessages extends AbstractIrCodegenBoxWasmTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath); + } + + public void testAllFilesPresentInExpressionAssertionMessages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); + } + } + @TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullCheckOnLambdaReturnValue") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)