Skip to content

Commit 19aa4f2

Browse files
committed
fix: added logic to render inner type converters when compound types are rendered
1 parent a31acc1 commit 19aa4f2

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

src/gen/compounds.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use paste::paste;
55
use uniffi_bindgen::interface::Type;
66

77
use super::oracle::{AsCodeType, DartCodeOracle};
8-
use crate::gen::render::{Renderable, TypeHelperRenderer};
8+
use crate::gen::render::{AsRenderable, Renderable, TypeHelperRenderer};
99

1010
macro_rules! impl_code_type_for_compound {
1111
($T:ty, $type_label_pattern:literal, $canonical_name_pattern: literal) => {
@@ -47,7 +47,13 @@ macro_rules! impl_renderable_for_compound {
4747
let inner_codetype = DartCodeOracle::find(self.inner());
4848
let inner_type_label = inner_codetype.type_label();
4949

50-
type_helper.include_once_check(&inner_codetype.canonical_name(), &self.inner()); // Add the Inner FFI Converter
50+
// Add the Inner FFI Converter and ensure it's rendered
51+
let inner_type_rendered = if !type_helper.include_once_check(&inner_codetype.canonical_name(), &self.inner()) {
52+
// If this is the first time we're seeing this inner type, render it now
53+
self.inner().as_renderable().render_type_helper(type_helper)
54+
} else {
55+
quote!()
56+
};
5157

5258
let cl_name = &format!($canonical_name_pattern, &inner_codetype.canonical_name());
5359
let type_label = &format!($type_label_pattern, &inner_type_label);
@@ -58,6 +64,8 @@ macro_rules! impl_renderable_for_compound {
5864

5965

6066
quote! {
67+
$inner_type_rendered
68+
6169
class $cl_name {
6270

6371
static $type_label lift( RustBuffer buf) {
@@ -124,7 +132,13 @@ macro_rules! impl_renderable_for_compound {
124132
let inner_codetype = self.inner().as_codetype();
125133
let inner_type_label = inner_codetype.type_label();
126134

127-
type_helper.include_once_check(&inner_codetype.canonical_name(), &self.inner()); // Add the Inner FFI Converter
135+
// Add the Inner FFI Converter and ensure it's rendered
136+
let inner_type_rendered = if !type_helper.include_once_check(&inner_codetype.canonical_name(), &self.inner()) {
137+
// If this is the first time we're seeing this inner type, render it now
138+
self.inner().as_renderable().render_type_helper(type_helper)
139+
} else {
140+
quote!()
141+
};
128142

129143
let cl_name = &format!($canonical_name_pattern, &inner_codetype.canonical_name());
130144
let type_label = &format!("List<{}>", &inner_type_label);
@@ -135,6 +149,8 @@ macro_rules! impl_renderable_for_compound {
135149

136150

137151
quote! {
152+
$inner_type_rendered
153+
138154
class $cl_name {
139155

140156
static $type_label lift( RustBuffer buf) {
@@ -233,8 +249,19 @@ impl Renderable for MapCodeType {
233249
let key_codetype = DartCodeOracle::find(self.key());
234250
let val_codetype = DartCodeOracle::find(self.value());
235251

236-
type_helper.include_once_check(&key_codetype.canonical_name(), self.key());
237-
type_helper.include_once_check(&val_codetype.canonical_name(), self.value());
252+
// Add the key and value FFI Converters and ensure they're rendered
253+
let key_type_rendered =
254+
if !type_helper.include_once_check(&key_codetype.canonical_name(), self.key()) {
255+
self.key().as_renderable().render_type_helper(type_helper)
256+
} else {
257+
quote!()
258+
};
259+
let val_type_rendered =
260+
if !type_helper.include_once_check(&val_codetype.canonical_name(), self.value()) {
261+
self.value().as_renderable().render_type_helper(type_helper)
262+
} else {
263+
quote!()
264+
};
238265

239266
let cl_name = &self.ffi_converter_name();
240267
let key_type_label_owned = key_codetype.type_label();
@@ -248,6 +275,9 @@ impl Renderable for MapCodeType {
248275
let val_conv = &val_conv_owned;
249276

250277
quote! {
278+
$key_type_rendered
279+
$val_type_rendered
280+
251281
class $cl_name {
252282
static Map<$key_type_label, $val_type_label> lift(RustBuffer buf) {
253283
return $cl_name.read(buf.asUint8List()).value;

0 commit comments

Comments
 (0)