Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing bug in Result<T> when T is a primitive that requires modification in the Kotlin code generation #693

Merged
merged 1 commit into from
Sep 17, 2024

Conversation

emarteca
Copy link
Contributor

The modification applied to primitives when returned as a result were specified in the wrong order in the Kotlin code generation.

For example, the following Rust:

pub fn test() -> Result<u32, ()> {
    todo!()
}

Generated the following Kotlin, with the bug specified with a comment:

      fun test(): Res<UInt, Unit> {
            val returnVal = lib.Why_test();
            if (returnVal.isOk == 1.toByte()) {
                return returnVal.union.ok.ok().toUInt() // THIS IS A BUG
            } else {
                return Err(Unit)
            }
        }

The buggy line should actually be return (returnVal.union.ok.toUInt()).ok() . This CL fixes the bug, for u32 and for all other primitives that require modification on return as a Res in Kotlin.

@emarteca emarteca marked this pull request as ready for review September 17, 2024 22:04
@emarteca
Copy link
Contributor Author

@jcrist1

@Manishearth Manishearth merged commit 7dc0d8e into rust-diplomat:main Sep 17, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants