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

native functions returning void appear to be unable to return results #119

Closed
davidhewitt opened this issue Nov 3, 2023 · 2 comments
Closed

Comments

@davidhewitt
Copy link
Contributor

I wrote this code (minimised):

duchess::java_package!
    package com.example;
    class MyService {
        public static native void initialise(java.lang.String);
    }
}

#[duchess::java_function(com.example.MyService::initialise)]
fn initialise(path: &java::lang::String) -> duchess::GlobalResult<()> { Ok(()) }

But I get the following compile error:

error[E0308]: mismatched types
   --> client-lib\src\service.rs:413:72
    |
413 |           #[duchess::java_function(com.example.NotebookService::initialise)]
    |                                                                 ^---------
    |                                                                 |
    |  _______________________________________________________________expected `()` because of return type
    | |
414 | |         fn initialise(path: &java::lang::String) -> duchess::GlobalResult<()> {
    | |                     ^- help: consider using a semicolon here: `;`
    | |_____________________|
    |                       expected `()`, found `Result<(), Error<Global<...>>>`
    |
    = note: expected unit type `()`
                    found enum `std::result::Result<(), duchess::Error<duchess::Global<Throwable>>>`

The compile error goes away if I replace void/GlobalResult<()> with java.lang.String/GlobalResult<String>.

@nikomatsakis
Copy link
Member

Thanks for this! I'll take a look. Curious.

@davidhewitt
Copy link
Contributor Author

Duplicate of #126

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

No branches or pull requests

2 participants