Skip to content

Commit

Permalink
Fix generated wrapper nested struct with static fn
Browse files Browse the repository at this point in the history
  • Loading branch information
roife committed Jul 16, 2024
1 parent 6a54d7c commit baba451
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
11 changes: 10 additions & 1 deletion engine/src/conversion/codegen_cpp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,22 @@ impl<'a> CppCodeGenerator<'a> {
}
},
CppFunctionBody::StaticMethodCall(ns, ty_id, fn_id) => {
// handle nested struct: A_B -> A::B
let full_name = QualifiedName::new(ns, ty_id.clone());
let using_nested_struct = self
.original_name_map
.get(&full_name)
.map_or("".to_string(), |nested_struct| {
format!("using {ty_id} = {nested_struct};")
});

let underlying_function_call = ns
.into_iter()
.cloned()
.chain([ty_id.to_string(), fn_id.to_string()].iter().cloned())
.join("::");
(
format!("{underlying_function_call}({arg_list})"),
format!("{using_nested_struct} {underlying_function_call}({arg_list})"),
"".to_string(),
false,
)
Expand Down
15 changes: 15 additions & 0 deletions integration-tests/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2603,6 +2603,21 @@ fn test_nested_with_destructor() {
run_test("", hdr, rs, &["A", "A_B"], &[]);
}

#[test]
fn test_nested_with_static_call() {
let hdr = indoc! {"
struct A {
struct B {
static void f() {}
};
};
"};
let rs = quote! {
ffi::A_B::new().within_unique_ptr();
};
run_test("", hdr, rs, &["A", "A_B"], &[]);
}

// Even without a `safety!`, we still need to generate a safe `fn drop`.
#[test]
fn test_destructor_no_safety() {
Expand Down

0 comments on commit baba451

Please sign in to comment.