// IGNORE_BACKEND: WASM // WASM_MUTE_REASON: TYPE_ISSUES // WITH_RUNTIME @Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE") @kotlin.jvm.JvmInline value class Result(val value: Any?) { fun exceptionOrNull(): Throwable? = when (value) { is Failure -> value.exception else -> null } public companion object { public inline fun success(value: T): Result = Result(value) public inline fun failure(exception: Throwable): Result = Result(Failure(exception)) } class Failure( val exception: Throwable ) } inline fun T.runCatching(block: T.() -> R): Result { return try { Result.success(block()) } catch (e: Throwable) { Result.failure(e) } } inline fun Result.getOrElse(onFailure: (exception: Throwable) -> R): R { return when (val exception = exceptionOrNull()) { null -> value as T else -> onFailure(exception) } } class A { fun f() = runCatching { "OK" }.getOrElse { throw it } } fun box(): String = A().f()