diff --git a/compiler/testData/codegen/box/assert/alwaysEnable.kt b/compiler/testData/codegen/box/assert/alwaysEnable.kt index 3c4db76e2b6..1f8152dec33 100644 --- a/compiler/testData/codegen/box/assert/alwaysEnable.kt +++ b/compiler/testData/codegen/box/assert/alwaysEnable.kt @@ -1,3 +1,4 @@ +// IGNORE_BACKEND: WASM // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // IGNORE_BACKEND: JS diff --git a/compiler/testData/codegen/box/casts/functions/isFunKBig.kt b/compiler/testData/codegen/box/casts/functions/isFunKBig.kt index dee2a1d601c..2e0ab284ef3 100644 --- a/compiler/testData/codegen/box/casts/functions/isFunKBig.kt +++ b/compiler/testData/codegen/box/casts/functions/isFunKBig.kt @@ -40,11 +40,11 @@ abstract class TestFnBase(val type: String) { abstract fun testBad(x: Any) protected fun assertIs(x: Any, condition: Boolean) { - assert(condition) { "x is $type: failed for $x" } + require(condition) { "x is $type: failed for $x" } } protected fun assertIsNot(x: Any, condition: Boolean) { - assert(condition) { "x !is $type: failed for $x" } + require(condition) { "x !is $type: failed for $x" } } } diff --git a/compiler/testData/codegen/box/casts/functions/reifiedIsFunKBig.kt b/compiler/testData/codegen/box/casts/functions/reifiedIsFunKBig.kt index 6b15aed1f77..dc4ecfb1aea 100644 --- a/compiler/testData/codegen/box/casts/functions/reifiedIsFunKBig.kt +++ b/compiler/testData/codegen/box/casts/functions/reifiedIsFunKBig.kt @@ -43,7 +43,7 @@ inline fun assertReifiedIs(x: Any, type: String) { catch (e: Throwable) { throw AssertionError("$x is $type: should not throw exceptions, got $e") } - assert(answer) { "$x is $type: failed" } + require(answer) { "$x is $type: failed" } } inline fun assertReifiedIsNot(x: Any, type: String) { @@ -54,7 +54,7 @@ inline fun assertReifiedIsNot(x: Any, type: String) { catch (e: Throwable) { throw AssertionError("$x !is $type: should not throw exceptions, got $e") } - assert(answer) { "$x !is $type: failed" } + require(answer) { "$x !is $type: failed" } } abstract class TestFnBase(val type: String) { diff --git a/compiler/testData/codegen/box/casts/functions/reifiedIsFunKSmall.kt b/compiler/testData/codegen/box/casts/functions/reifiedIsFunKSmall.kt index 6c5234b6cd2..618af61c4fd 100644 --- a/compiler/testData/codegen/box/casts/functions/reifiedIsFunKSmall.kt +++ b/compiler/testData/codegen/box/casts/functions/reifiedIsFunKSmall.kt @@ -16,7 +16,7 @@ inline fun assertReifiedIs(x: Any, type: String) { catch (e: Throwable) { throw AssertionError("$x is $type: should not throw exceptions, got $e") } - assert(answer) { "$x is $type: failed" } + require(answer) { "$x is $type: failed" } } inline fun assertReifiedIsNot(x: Any, type: String) { @@ -27,7 +27,7 @@ inline fun assertReifiedIsNot(x: Any, type: String) { catch (e: Throwable) { throw AssertionError("$x !is $type: should not throw exceptions, got $e") } - assert(answer) { "$x !is $type: failed" } + require(answer) { "$x !is $type: failed" } } fun box(): String { diff --git a/compiler/testData/codegen/box/casts/functions/safeAsFunKBig.kt b/compiler/testData/codegen/box/casts/functions/safeAsFunKBig.kt index 0368ae2c5ce..a32418c6f37 100644 --- a/compiler/testData/codegen/box/casts/functions/safeAsFunKBig.kt +++ b/compiler/testData/codegen/box/casts/functions/safeAsFunKBig.kt @@ -38,7 +38,7 @@ val fns = arrayOf(::fn0, ::fn1, ::fn2, ::fn3, ::fn4, ::fn5, ::fn6, ::fn7, : inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) { try { val x = cast() - assert(x == null) { "$operation: should return null, got $x" } + require(x == null) { "$operation: should return null, got $x" } } catch (e: Throwable) { throw AssertionError("$operation: should not throw exceptions, got $e") @@ -48,7 +48,7 @@ inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) { inline fun safeAsReturnsNonNull(operation: String, cast: () -> Any?) { try { val x = cast() - assert(x != null) { "$operation: should return non-null" } + require(x != null) { "$operation: should return non-null" } } catch (e: Throwable) { throw AssertionError("$operation: should not throw exceptions, got $e") diff --git a/compiler/testData/codegen/box/casts/functions/safeAsFunKSmall.kt b/compiler/testData/codegen/box/casts/functions/safeAsFunKSmall.kt index 67b3399f4cc..75774ca565c 100644 --- a/compiler/testData/codegen/box/casts/functions/safeAsFunKSmall.kt +++ b/compiler/testData/codegen/box/casts/functions/safeAsFunKSmall.kt @@ -11,7 +11,7 @@ fun fn1(x: Any) {} inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) { try { val x = cast() - assert(x == null) { "$operation: should return null, got $x" } + require(x == null) { "$operation: should return null, got $x" } } catch (e: Throwable) { throw AssertionError("$operation: should not throw exceptions, got $e") @@ -21,7 +21,7 @@ inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) { inline fun safeAsReturnsNonNull(operation: String, cast: () -> Any?) { try { val x = cast() - assert(x != null) { "$operation: should return non-null" } + require(x != null) { "$operation: should return non-null" } } catch (e: Throwable) { throw AssertionError("$operation: should not throw exceptions, got $e") diff --git a/compiler/testData/codegen/box/casts/mutableCollections/weirdMutableCasts.kt b/compiler/testData/codegen/box/casts/mutableCollections/weirdMutableCasts.kt index 4b9b300dace..b45021ee6fa 100644 --- a/compiler/testData/codegen/box/casts/mutableCollections/weirdMutableCasts.kt +++ b/compiler/testData/codegen/box/casts/mutableCollections/weirdMutableCasts.kt @@ -1,8 +1,3 @@ -// IGNORE_BACKEND: JS_IR -// IGNORE_BACKEND: JS_IR_ES6 -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - // WITH_STDLIB fun unsupported(): Nothing = throw UnsupportedOperationException() @@ -41,7 +36,7 @@ inline fun asSucceeds(operation: String, cast: () -> Unit) { inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) { try { val x = cast() - assert(x == null) { "$operation: should return null, got $x" } + require(x == null) { "$operation: should return null, got $x" } } catch (e: Throwable) { throw AssertionError("$operation: should not throw exceptions, got $e") @@ -51,7 +46,7 @@ inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) { inline fun safeAsReturnsNonNull(operation: String, cast: () -> Any?) { try { val x = cast() - assert(x != null) { "$operation: should return non-null" } + require(x != null) { "$operation: should return non-null" } } catch (e: Throwable) { throw AssertionError("$operation: should not throw exceptions, got $e") @@ -111,10 +106,10 @@ inline fun reifiedSafeAsReturnsNull(x: Any?, operation: String) { fun box(): String { val w: Any = Weird() - assert(w is Iterator<*>) { "w is Iterator<*>" } - assert(w !is MutableIterator<*>) { "w !is MutableIterator<*>" } - assert(w is MutableIterable<*>) { "w is MutableIterable<*>" } - assert(w is MutableMap.MutableEntry<*, *>) { "w is MutableMap.MutableEntry<*, *>" } + require(w is Iterator<*>) { "w is Iterator<*>" } + require(w !is MutableIterator<*>) { "w !is MutableIterator<*>" } + require(w is MutableIterable<*>) { "w is MutableIterable<*>" } + require(w is MutableMap.MutableEntry<*, *>) { "w is MutableMap.MutableEntry<*, *>" } asSucceeds("w as Iterator<*>") { w as Iterator<*> } asFailsWithCCE("w as MutableIterator<*>") { w as MutableIterator<*> } @@ -126,10 +121,10 @@ fun box(): String { safeAsReturnsNonNull("w as? MutableIterable<*>") { w as? MutableIterable<*> } safeAsReturnsNonNull("w as? MutableMap.MutableEntry<*, *>") { w as? MutableMap.MutableEntry<*, *> } - assert(reifiedIs>(w)) { "reifiedIs>(w)" } - assert(reifiedIsNot>(w)) { "reifiedIsNot>(w)" } - assert(reifiedIs>(w)) { "reifiedIs>(w)" } - assert(reifiedIs>(w)) { "reifiedIs>(w)" } + require(reifiedIs>(w)) { "reifiedIs>(w)" } + require(reifiedIsNot>(w)) { "reifiedIsNot>(w)" } + require(reifiedIs>(w)) { "reifiedIs>(w)" } + require(reifiedIs>(w)) { "reifiedIs>(w)" } reifiedAsSucceeds>(w, "reified w as Iterator<*>") reifiedAsFailsWithCCE>(w, "reified w as MutableIterator<*>") diff --git a/compiler/testData/codegen/box/coroutines/doubleColonExpressionsGenerationInBuilderInference.kt b/compiler/testData/codegen/box/coroutines/doubleColonExpressionsGenerationInBuilderInference.kt index ab90db54f11..4439fb5a7b5 100644 --- a/compiler/testData/codegen/box/coroutines/doubleColonExpressionsGenerationInBuilderInference.kt +++ b/compiler/testData/codegen/box/coroutines/doubleColonExpressionsGenerationInBuilderInference.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: JS, JS_IR -// IGNORE_BACKEND: JS_IR_ES6 // WITH_STDLIB package a.b @@ -22,7 +20,7 @@ fun test() { } val size = a.toList().size - assert(size == 5) { "actual size: $size"} + require(size == 5) { "actual size: $size"} } fun box(): String { diff --git a/compiler/testData/codegen/box/ranges/safeCallRangeTo.kt b/compiler/testData/codegen/box/ranges/safeCallRangeTo.kt index 103df9ba788..d0f5a6117c4 100644 --- a/compiler/testData/codegen/box/ranges/safeCallRangeTo.kt +++ b/compiler/testData/codegen/box/ranges/safeCallRangeTo.kt @@ -15,10 +15,10 @@ fun dougleRange(x: Double?, y: Double) = x?.rangeTo(y) inline fun testSafeRange(x: T, y: T, expectStr: String, safeRange: (T?, T) -> R?) { val rNull = safeRange(null, y) - assert (rNull == null) { "${T::class.simpleName}: Expected: null, got $rNull" } + require (rNull == null) { "${T::class.simpleName}: Expected: null, got $rNull" } val rxy = safeRange(x, y) - assert (rxy?.toString() == expectStr) { "${T::class.simpleName}: Expected: $expectStr, got $rxy" } + require (rxy?.toString() == expectStr) { "${T::class.simpleName}: Expected: $expectStr, got $rxy" } } fun box(): String { diff --git a/compiler/testData/codegen/box/regressions/kt2246.kt b/compiler/testData/codegen/box/regressions/kt2246.kt index 044ba159714..73aafe18274 100644 --- a/compiler/testData/codegen/box/regressions/kt2246.kt +++ b/compiler/testData/codegen/box/regressions/kt2246.kt @@ -1,3 +1,4 @@ +// IGNORE_BACKEND: WASM // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: muted automatically, investigate should it be ran for JS or not diff --git a/compiler/testData/codegen/box/reified/instanceof.kt b/compiler/testData/codegen/box/reified/instanceof.kt index 2db9dae9d79..10ff3051655 100644 --- a/compiler/testData/codegen/box/reified/instanceof.kt +++ b/compiler/testData/codegen/box/reified/instanceof.kt @@ -1,8 +1,3 @@ -// IGNORE_BACKEND: JS_IR -// IGNORE_BACKEND: JS_IR_ES6 -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - // WITH_STDLIB inline fun isinstance(x: Any?): Boolean { @@ -10,9 +5,9 @@ inline fun isinstance(x: Any?): Boolean { } fun box(): String { - assert(isinstance("abc")) - assert(isinstance(1)) - assert(!isinstance("abc")) + require(isinstance("abc")) + require(isinstance(1)) + require(!isinstance("abc")) return "OK" } diff --git a/compiler/testData/codegen/box/reified/newArrayInt.kt b/compiler/testData/codegen/box/reified/newArrayInt.kt index aed42bedd0d..c2c0f4806f2 100644 --- a/compiler/testData/codegen/box/reified/newArrayInt.kt +++ b/compiler/testData/codegen/box/reified/newArrayInt.kt @@ -1,8 +1,3 @@ -// IGNORE_BACKEND: JS_IR -// IGNORE_BACKEND: JS_IR_ES6 -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - // WITH_STDLIB inline fun createArray(n: Int, crossinline block: () -> T): Array { @@ -13,6 +8,6 @@ fun box(): String { val x = createArray(5) { 3 } - assert(x.all { it == 3 }) + require(x.all { it == 3 }) return "OK" } diff --git a/compiler/testData/codegen/box/reified/recursiveNewArray.kt b/compiler/testData/codegen/box/reified/recursiveNewArray.kt index 518927b44dc..09e4a599912 100644 --- a/compiler/testData/codegen/box/reified/recursiveNewArray.kt +++ b/compiler/testData/codegen/box/reified/recursiveNewArray.kt @@ -1,8 +1,3 @@ -// IGNORE_BACKEND: JS_IR -// IGNORE_BACKEND: JS_IR_ES6 -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - // WITH_STDLIB inline fun createArray(n: Int, crossinline block: () -> T): Array { @@ -18,6 +13,6 @@ inline fun recursive( fun box(): String { val x = recursive(){ "abc" } - assert(x.all { it == "abc" }) + require(x.all { it == "abc" }) return "OK" } diff --git a/compiler/testData/codegen/box/reified/sameIndexRecursive.kt b/compiler/testData/codegen/box/reified/sameIndexRecursive.kt index 0d53d587924..1ad0d30b9e0 100644 --- a/compiler/testData/codegen/box/reified/sameIndexRecursive.kt +++ b/compiler/testData/codegen/box/reified/sameIndexRecursive.kt @@ -1,8 +1,3 @@ -// IGNORE_BACKEND: JS_IR -// IGNORE_BACKEND: JS_IR_ES6 -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - // WITH_STDLIB inline fun createArray(n: Int, crossinline block: () -> Pair): Pair, Array> { @@ -19,9 +14,9 @@ fun box(): String { val y = createArray(5) { Pair(1, "test") } val x = recursive(){ "abc" } - assert(y.first.all { it == 1 } ) - assert(y.second.all { it == "test" }) - assert(x.first.all { it == "abc" }) - assert(x.second.all { it == "abc" }) + require(y.first.all { it == 1 } ) + require(y.second.all { it == "test" }) + require(x.first.all { it == "abc" }) + require(x.second.all { it == "abc" }) return "OK" } diff --git a/libraries/stdlib/wasm/src/kotlin/Assertions.kt b/libraries/stdlib/wasm/src/kotlin/Assertions.kt index 680fdbcfc29..9053880755f 100644 --- a/libraries/stdlib/wasm/src/kotlin/Assertions.kt +++ b/libraries/stdlib/wasm/src/kotlin/Assertions.kt @@ -10,14 +10,14 @@ package kotlin /** * Throws an [AssertionError] if the [value] is false. */ -public fun assert(value: Boolean) { +internal fun assert(value: Boolean) { assert(value) { "Assertion failed" } } /** * Throws an [AssertionError] calculated by [lazyMessage] if the [value] is false. */ -public fun assert(value: Boolean, lazyMessage: () -> Any) { +internal fun assert(value: Boolean, lazyMessage: () -> Any) { if (!value) { val message = lazyMessage() throw AssertionError(message)