Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent infinite recursion on visitor2 #940

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/common/src/typegraph/visitor2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ fn traverse_types_with_path<'tg, A, V, E>(
where
V: Fn(VisitorContext<'tg>, &mut A) -> Result<VisitNext, E>,
{
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
{
Expand Down
1 change: 1 addition & 0 deletions tests/metagen/typegraphs/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])}
Expand Down
Loading