-
Notifications
You must be signed in to change notification settings - Fork 271
Throw error when objects are passed instead of traits (#2649) #2685
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
Conversation
30e80d6
to
c402a29
Compare
The corner case here is when an object implements a Rust-only trait. In the updated coverall fixture we have the following Python classes: - StringUtilProtocol - interface for the trait - StringUtil - object that implements the trait via rust calls - StringUtilObject - exported Rust object that imprements the trait Before `StringUtilObject` would inherit from `StringUtil`, which isn't correct conceptually and in practice it means that the Python code will try to lower the handle into a function that expects `Arc<dyn StructUtil>` when the handle was actually for `Arc<StringUtilObject>`, once Rust tries to use the arc a segfault will happen soon after. Now `StringUtilObject` inherits from `StringUtilProtocol` and we don't have the segfault. I tried to add Kotlin and Swift tests here, but it doesn't work because they throw a type error as soon as you try making that call.
c402a29
to
c2757eb
Compare
Just to be clear, when the trait is If that is intended it might be worthwhile to a add a fixture testing that it does indeed work. Also might be worth an explanation about the extra boundary crosses in the docs. I can create a separate PR for that if desired. If not intended, I think that would be a useful feature to support. The primary use case I have in mind is for testing the generated code from Rust. Not sure what this would look like in Swift, Kotlin, or other 3rd party languages though. |
That's working as intended.
The more I think about it, the more I think the real fix is to swap things and make trait interfaces without Then regular, non-trait, objects would be the odd one out. There, (I thought there was already an issue for this, but I can't find it). |
Since, we're pretty close to a release, I'm thinking I'll put up a PR once the next cycle starts. |
#[uniffi::export] | ||
pub fn concat_with_string_util(string_util: Arc<dyn StringUtil>, a: &str, b: &str) -> String { | ||
string_util.concat(a, b) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up kinda accidentally adding these kinds of tests here too. I might have a go at consolidating that and this coveralls traits stuff into a dedicated traits fixture?
I think I agree with that - but it's difficult to visualize exactly - it'd be great to see concrete class mockups. |
Made #2689 to continue the discussion/work on the trait names. Let's merge this one. |
The corner case here is when an object implements a Rust-only trait. In the updated coverall fixture we have the following Python classes:
Before
StringUtilObject
would inherit fromStringUtil
, which isn't correct conceptually and in practice it means that the Python code will try to lower the handle into a function that expectsArc<dyn StructUtil>
when the handle was actually forArc<StringUtilObject>
, once Rust tries to use the arc a segfault will happen soon after.Now
StringUtilObject
inherits fromStringUtilProtocol
and we don't have the segfault.I tried to add Kotlin and Swift tests here, but it doesn't work because they throw a type error as soon as you try making that call.