From 2188d1fad6abfb0e19f68624b2e4908e43ae8f0f Mon Sep 17 00:00:00 2001 From: carlos-alm Date: Sun, 17 May 2026 22:43:16 -0600 Subject: [PATCH] refactor(verilog): use if let Some in for-loops instead of ? The `?` operator inside a `for` loop short-circuits the entire enclosing function on the first `None`, not just the current iteration. In practice `node.child(i)` returns `Some` for every `i < child_count()`, so this was harmless, but `if let Some(child) = node.child(i)` is more defensively correct and matches the pattern already used in `handle_package_import` and `handle_include_directive`. Closes #1118 --- .../codegraph-core/src/extractors/verilog.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/codegraph-core/src/extractors/verilog.rs b/crates/codegraph-core/src/extractors/verilog.rs index 1034fc5c..fe804b0f 100644 --- a/crates/codegraph-core/src/extractors/verilog.rs +++ b/crates/codegraph-core/src/extractors/verilog.rs @@ -148,9 +148,10 @@ fn find_class_name(node: &Node, source: &[u8]) -> Option { return Some(text.to_string()); } for i in 0..node.child_count() { - let child = node.child(i)?; - if child.kind() == "class_identifier" { - return Some(extract_identifier_text(&child, source)); + if let Some(child) = node.child(i) { + if child.kind() == "class_identifier" { + return Some(extract_identifier_text(&child, source)); + } } } None @@ -161,12 +162,13 @@ fn find_class_name(node: &Node, source: &[u8]) -> Option { /// `class_identifier > simple_identifier`. fn find_class_superclass(node: &Node, source: &[u8]) -> Option { for i in 0..node.child_count() { - let child = node.child(i)?; - if child.kind() == "class_type" { - if let Some(id) = find_child(&child, "class_identifier") { - return Some(extract_identifier_text(&id, source)); + if let Some(child) = node.child(i) { + if child.kind() == "class_type" { + if let Some(id) = find_child(&child, "class_identifier") { + return Some(extract_identifier_text(&id, source)); + } + return Some(node_text(&child, source).trim().to_string()); } - return Some(node_text(&child, source).trim().to_string()); } } None