From 319fc4bcf0238e3956e523fe164b137b2bdb8389 Mon Sep 17 00:00:00 2001 From: Natoandro Date: Mon, 16 Dec 2024 06:07:28 +0300 Subject: [PATCH] check for cycles in visitor2 --- src/common/src/typegraph/visitor2.rs | 9 ++++++++- tests/metagen/typegraphs/python.py | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/common/src/typegraph/visitor2.rs b/src/common/src/typegraph/visitor2.rs index 82804b844..c3b327675 100644 --- a/src/common/src/typegraph/visitor2.rs +++ b/src/common/src/typegraph/visitor2.rs @@ -90,8 +90,15 @@ fn traverse_types_with_path<'tg, A, V, E>( where V: Fn(VisitorContext<'tg>, &mut A) -> Result, { + let cyclic = path.borrow().iter().any(|segment| segment.from == type_idx); + if cyclic { + return Ok(TraverseOutput { + accumulator, + stop: false, + }); + } + let type_node = &tg.types[type_idx as usize]; - // TODO check for cycles // visit current { diff --git a/tests/metagen/typegraphs/python.py b/tests/metagen/typegraphs/python.py index e2f89bfd2..ed1478b97 100644 --- a/tests/metagen/typegraphs/python.py +++ b/tests/metagen/typegraphs/python.py @@ -18,6 +18,7 @@ def example(g: Graph): "email": t.email().optional(), "list_integer": t.list(t.integer()), "opt_union_flat": t.union([t.integer(), t.float()]).optional(), + "file": t.file().optional(), "reference": t.list(g.ref("Example")).optional(), "nested_ref": t.struct( {"either": t.either([g.ref("Example"), references])}