Implement new assert semantics in back-end
Previously, assert was just a regular function and its argument used to be computed on each call (even if assertions are disabled on JVM). This change adds support for 3 new behaviours of assert: * always-enable (independently from -ea on JVM) * always-disable (independently from -ea JVM) * runtime/jvm (compile the calls like javac generates assert-operator) * legacy (leave current eager semantics) - this already existed Default behaviour is legacy for now. The behavior is changed based on -Xassertions flag. #KT-7540: Fixed
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.config
|
||||
|
||||
enum class JVMAssertionsMode(val description: String) {
|
||||
ALWAYS_ENABLE("always-enable"),
|
||||
ALWAYS_DISABLE("always-disable"),
|
||||
JVM("jvm"),
|
||||
LEGACY("legacy");
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val DEFAULT = LEGACY
|
||||
|
||||
@JvmStatic
|
||||
fun fromStringOrNull(string: String?) = values().find { it.description == string }
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,8 @@ public class JVMConfigurationKeys {
|
||||
CompilerConfigurationKey.create("disable not-null call receiver assertions");
|
||||
public static final CompilerConfigurationKey<Boolean> DISABLE_PARAM_ASSERTIONS =
|
||||
CompilerConfigurationKey.create("disable not-null parameter assertions");
|
||||
public static final CompilerConfigurationKey<JVMAssertionsMode> ASSERTIONS_MODE =
|
||||
CompilerConfigurationKey.create("assertions mode");
|
||||
public static final CompilerConfigurationKey<JVMConstructorCallNormalizationMode> CONSTRUCTOR_CALL_NORMALIZATION_MODE =
|
||||
CompilerConfigurationKey.create("constructor call normalization mode");
|
||||
public static final CompilerConfigurationKey<Boolean> NO_EXCEPTION_ON_EXPLICIT_EQUALS_FOR_BOXED_NULL =
|
||||
|
||||
Reference in New Issue
Block a user