JVM: change logic of applying KT-57570 behavior a bit

If `-Xno-unified-null-checks` is specified, do not throw exceptions, but
rather revert to the old behavior, with source code in exception
messages.

Note that `-Xno-unified-null-checks` is a flag which enables behavior of
Kotlin 1.3. It can be removed once we no longer support API version 1.3.
This commit is contained in:
Alexander Udalov
2023-05-22 15:48:04 +02:00
committed by Space Team
parent 5d3fe7547a
commit ad1dfd5cb9
2 changed files with 10 additions and 11 deletions
@@ -315,16 +315,15 @@ 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)
).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 unifiedNullChecks: Boolean =
languageVersionSettings.apiVersion >= ApiVersion.KOTLIN_1_4 &&
!configuration.getBoolean(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS)
val noSourceCodeInNotNullAssertionExceptions: Boolean =
languageVersionSettings.supportsFeature(LanguageFeature.NoSourceCodeInNotNullAssertionExceptions)
// This check is needed because we generate calls to `Intrinsics.checkNotNull` which is only available since 1.4
// (when unified null checks were introduced).
&& unifiedNullChecks
val generateSmapCopyToAnnotation: Boolean = !configuration.getBoolean(JVMConfigurationKeys.NO_SOURCE_DEBUG_EXTENSION)
val functionsWithInlineClassReturnTypesMangled: Boolean =
@@ -764,7 +764,7 @@ private class TypeOperatorLowering(private val backendContext: JvmBackendContext
}
private fun IrBuilderWithScope.computeNotNullAssertionText(typeOperatorCall: IrTypeOperatorCall): String? {
if (backendContext.state.languageVersionSettings.supportsFeature(LanguageFeature.NoSourceCodeInNotNullAssertionExceptions)) {
if (backendContext.state.noSourceCodeInNotNullAssertionExceptions) {
return when (val argument = typeOperatorCall.argument) {
is IrCall -> "${argument.symbol.owner.name.asString()}(...)"
is IrGetField -> argument.symbol.owner.name.asString()