diff --git a/python/openapi/src/com/jetbrains/python/Result.kt b/python/openapi/src/com/jetbrains/python/Result.kt index 6c7d526474c3..c6c2fa6dcb1c 100644 --- a/python/openapi/src/com/jetbrains/python/Result.kt +++ b/python/openapi/src/com/jetbrains/python/Result.kt @@ -87,14 +87,21 @@ sealed class Result { /** * Like Rust `unwrap`: returns result or throws exception. Use when error is unexpected */ - fun orThrow(onError: (ERR) -> Throwable = { e -> if (e is Throwable) e else AssertionError(e) }): SUCC { + fun orThrow(onError: (ERR) -> Throwable = { e -> if (e is Throwable) e else AssertionError(e) }): SUCC { when (this) { is Success -> return result is Failure -> throw onError(this.error) } } + + // To be backward compatible with Kotlin result + companion object { + fun success(value: S) = Success(value) + fun failure(error: E) = Failure(error) + } } + /** * Maps success result to another one with same error * ```kotlin