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

Callback interface method cannot return callback interface #1947

Closed
bancek opened this issue Jan 21, 2024 · 2 comments
Closed

Callback interface method cannot return callback interface #1947

bancek opened this issue Jan 21, 2024 · 2 comments

Comments

@bancek
Copy link
Contributor

bancek commented Jan 21, 2024

In uniffi 25 a callback interface cannot return another callback interface. This used to work up to uniffi 24.3.

Guessing this was broken in #1766 by @bendk .

test.udl:

callback interface Stream {
  bytes read();
};

callback interface StreamProvider {
  Stream stream();
};

namespace test {
};

lib.rs:

use std::fmt::Debug;

pub trait Stream: Send + Sync + Debug {
    fn read(&self) -> Vec<u8>;
}

pub trait StreamProvider: Send + Sync + Debug {
    fn stream(&self) -> Box<dyn Stream>;
}

uniffi::include_scaffolding!("test");

Error:

    Checking uniffi-liftreturn-bug v0.1.0 (/Users/luka/uniffi-liftreturn-bug)
error[E0277]: the trait bound `Box<dyn Stream>: LiftReturn<UniFfiTag>` is not satisfied
   --> /Users/luka/uniffi-liftreturn-bug/target/debug/build/uniffi-liftreturn-bug-b39dd21c4e7a5173/out/test.uniffi.rs:124:69
    |
124 |         FOREIGN_CALLBACK_STREAMPROVIDER_INTERNALS.invoke_callback::<Box<dyn r#Stream>, crate::UniFfiTag>(self.handle, 1, args_rbuf)
    |                                                   ---------------   ^^^^^^^^^^^^^^^^^ the trait `LiftReturn<UniFfiTag>` is not implemented for `Box<dyn Stream>`
    |                                                   |
    |                                                   required by a bound introduced by this call
    |
    = help: the following other types implement trait `LiftReturn<UT>`:
              bool
              i8
              i16
              i32
              i64
              u8
              u16
              u32
            and 13 others
note: required by a bound in `ForeignCallbackInternals::invoke_callback`
   --> /Users/luka/.cargo/registry/src/index.crates.io-6f17d22bba15001f/uniffi_core-0.25.3/src/ffi/callbackinterface.rs:172:12
    |
170 |     pub fn invoke_callback<R, UniFfiTag>(&self, handle: u64, method: u32, args: RustBuffer) -> R
    |            --------------- required by a bound in this associated function
171 |     where
172 |         R: LiftReturn<UniFfiTag>,
    |            ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ForeignCallbackInternals::invoke_callback`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `uniffi-liftreturn-bug` (lib) due to previous error
bendk added a commit to bendk/uniffi-rs that referenced this issue Jan 22, 2024
…a#1947)

As mentioned in the `fnsig` code, I feel like this is a bid of a
band-aid.  However, I think a real fix would require significant changes
to the FFI trait system and I don't want to do that so close to the
v0.26 release.
bendk added a commit to bendk/uniffi-rs that referenced this issue Jan 22, 2024
…a#1947)

The easy part was implementing `LiftReturn`.  The hard part was figuring
out how to handle TYPE_ID_META in the metadata code.  In general, we
have an issue: should we get that from `Lift`/`LiftReturn` or
`Lower`/`LowerReturn`.

As mentioned in the `fnsig` code, I feel like this is a bid of a
band-aid.  However, I think a real fix would require significant changes
to the FFI trait system and I don't want to do that so close to the
v0.26 release.
bendk added a commit to bendk/uniffi-rs that referenced this issue Jan 22, 2024
…a#1947)

The easy part was implementing `LiftReturn`.  The hard part was figuring
out how to handle TYPE_ID_META in the metadata code.  In general, we
have an issue: should we get that from `Lift`/`LiftReturn` or
`Lower`/`LowerReturn`.

As mentioned in the `fnsig` code, I feel like this is a bid of a
band-aid.  However, I think a real fix would require significant changes
to the FFI trait system and I don't want to do that so close to the
v0.26 release.
bendk added a commit that referenced this issue Jan 22, 2024
The easy part was implementing `LiftReturn`.  The hard part was figuring
out how to handle TYPE_ID_META in the metadata code.  In general, we
have an issue: should we get that from `Lift`/`LiftReturn` or
`Lower`/`LowerReturn`.

As mentioned in the `fnsig` code, I feel like this is a bid of a
band-aid.  However, I think a real fix would require significant changes
to the FFI trait system and I don't want to do that so close to the
v0.26 release.
@mhammond
Copy link
Member

Fixed in 6f9d65a

@bancek
Copy link
Contributor Author

bancek commented Jan 27, 2024

Thank you 😊

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