stdlib: Add assert() functions.

This commit is contained in:
Ilya Matveev
2017-03-10 15:32:45 +03:00
committed by ilmat192
parent a181b0301e
commit 30be84cd55
2 changed files with 23 additions and 0 deletions
@@ -0,0 +1,20 @@
package kotlin
/**
* Throws an [AssertionError] if the [value] is false
* and runtime assertions have been enabled during compilation.
*/
public inline fun assert(value: Boolean) {
assert(value) { "Assertion failed" }
}
/**
* Throws an [AssertionError] calculated by [lazyMessage] if the [value] is false
* and runtime assertions have been enabled during compilation.
*/
public inline fun assert(value: Boolean, lazyMessage: () -> Any) {
if (!value) {
val message = lazyMessage()
throw AssertionError(message)
}
}
@@ -142,6 +142,9 @@ public class AssertionError : Error {
constructor(message: String) : super(message) {
}
constructor(message: Any) : super(message.toString()) {
}
constructor(message: String, cause: Throwable) : super(message, cause) {
}
}