Skip to content

Commit

Permalink
Add more sanity checks to uniffi_bindgen
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte authored and bendk committed Oct 25, 2022
1 parent 7d94b65 commit 89b9dd8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions uniffi_bindgen/src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,13 @@ impl ComponentInterface {
}
}
}

for ty in self.iter_types() {
if let Type::Unresolved { name } = ty {
bail!("Type `{name}` should be resolved at this point");
}
}

Ok(())
}

Expand Down
5 changes: 5 additions & 0 deletions uniffi_bindgen/src/interface/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ impl TypeUniverse {
///
/// This will fail if you try to add a name for which an existing type definition exists.
pub fn add_type_definition(&mut self, name: &str, type_: Type) -> Result<()> {
if let Type::Unresolved { name: name_ } = &type_ {
assert_eq!(name, name_);
bail!("attempted to add type definition of Unresolved for `{name}`");
}

if resolve_builtin_type(name).is_some() {
bail!(
"please don't shadow builtin types ({name}, {})",
Expand Down
2 changes: 1 addition & 1 deletion uniffi_bindgen/src/macro_metadata/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ pub fn add_to_ci(
}

iface.resolve_types()?;
iface.check_consistency()?;
iface.derive_ffi_funcs()?;
iface.check_consistency()?;

Ok(())
}

0 comments on commit 89b9dd8

Please sign in to comment.