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 code generation for Result<bool> in Kotlin #692

Merged
merged 1 commit into from
Sep 17, 2024

Conversation

emarteca
Copy link
Contributor

The general case for dealing with Result in Kotlin doesn't work for booleans.
Previously, generating the Kotlin code for a Rust function that returned a Result<bool> would be as follows:

Rust

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

Generated Kotlin (with the bug specified in a comment):

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

For booleans, this error line should instead be return (returnVal.union.ok > 0).ok() . This CL fixes this problem.

@emarteca
Copy link
Contributor Author

@jcrist1

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

oh hang on, the same bug shows up for some other primitive types too. let me fix them all in this PR

@Manishearth Manishearth merged commit c3bf8e3 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