- Annotate Result#{value,error} direct access as unsafe by @hoc081098 (db45c67)
- For full context and discussion on this topic, please read through the PR by @hoc081098 at #123, and the initial discussion presented by @kirillzh in #104.
Library consumers that directly access either Result.value
or Result.error
, e.g. in the situation they are extending the library to implement their own functionality, must now opt-in to unsafe access of these properties.
Failure to do so will result in a compilation error:

There are three ways to opt-in:
-
On a function-level
@OptIn(UnsafeResultValueAccess::class) fun myFunctionThatAccessesValueDirectly() { ... }
-
On a file-level:
@file:OptIn(UnsafeResultValueAccess::class) fun myFunctionThatAccessesValueDirectly() { ... } fun anotherFunctionThatAccessesValueDirectly() { ... }
-
On a project-level in
build.gradle.kts
kotlin { compilerOptions { optIn.add("com.github.michaelbull.result.annotation.UnsafeResultValueAccess") optIn.add("com.github.michaelbull.result.annotation.UnsafeResultErrorAccess") } }