To generate the array, we're calling generate_type on top-level type
that came to this function which *IS* an array. That creates an infinite
loop and thus causing a stack overflow.
The fix is simple, use type that the array holds (e.g. Int) and not the
type of array itself (which is Array<Int> in this case).
---
src/generator/c.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/generator/c.rs b/src/generator/c.rs
index 178de85..7d7618d 100644
--- a/src/generator/c.rs
+++ b/src/generator/c.rs
@@ -53,13 +53,13 @@ pub(super) fn generate_type(t: Either<Variable, Option<Type>>) -> String {
Type::Any => "void *".into(),
Type::Bool => "bool".into(),
Type::Struct(_) => todo!(),
- Type::Array(_) => match name {
+ Type::Array(t) => match name {
Some(n) => format!(
"{T} {N}[]",
- T = generate_type(Either::Right(Some(t))),
+ T = generate_type(Either::Right(Some(*t))),
N = n
),
- None => format!("{}[]", generate_type(Either::Right(Some(t)))),
+ None => format!("{}[]", generate_type(Either::Right(Some(*t)))),
},
},
None => "void".into(),
--
2.30.1