Open jnbooth opened 3 months ago
Thanks for reporting this.
We generate a __swift_bridge__Option_MyEnumName
type in the module that declares the enum.
The #[already_declared]
module is trying to make use of that type, but it isn't visible.
The module that contains the #[already_declared]
enum needs to look for __swift_bridge__Option_MyEnumName
in the super::
module.
Here are steps to solve this:
Add a new #[already_declared]
codegen test module for an extern "Rust" function that returns an Option<AlreadyDeclaredEnum>
Similar to this but for an Option<SomeEnum>
https://github.com/chinedufn/swift-bridge/blob/ecd3b974754e32fc951b8bc4098ecef84e974821/crates/swift-bridge-ir/src/codegen/codegen_tests/already_declared_attribute_codegen_tests.rs#L168-L232
Add an integration test for calling a Rust function that returns an Option<AlreadyDeclaredEnum>
.
Similar to:
Update the codegen to use super::__swift_bridge__Option_SomeTransparentEnum
when the enum is already_declared
.
pub fn ffi_option_name_tokens(&self) -> TokenStream {
let maybe_super = if self.already_declared {
"super::"
} else {
""
};
let name = Ident::new(
&format!("{maybe_super}{}Option_{}", SWIFT_BRIDGE_PREFIX, self.name),
self.name.span(),
);
quote! { #name }
}
Minimal reproduction:
This fails to compile due to: