Skip to content

Commit dd3b1fe

Browse files
authored
refactor(objc): use if let Some in for-loop instead of ? (#1156)
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 is harmless today, but `if let Some(child) = node.child(i)` is more defensively correct and matches the pattern used in the rest of the extractors after the Verilog sweep in #1155. Closes #1116
1 parent d255297 commit dd3b1fe

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

  • crates/codegraph-core/src/extractors

crates/codegraph-core/src/extractors/objc.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,14 @@ fn collect_class_members(class_node: &Node, source: &[u8]) -> Vec<Definition> {
493493
fn extract_property_name(prop_node: &Node, source: &[u8]) -> Option<String> {
494494
let struct_decl = find_child(prop_node, "struct_declaration")?;
495495
for i in 0..struct_decl.child_count() {
496-
let child = struct_decl.child(i)?;
497-
if child.kind() == "struct_declarator" {
498-
// struct_declarator > pointer_declarator > identifier
499-
// or struct_declarator > identifier (no pointer)
500-
let name = unwrap_property_declarator(&child, source);
501-
if !name.is_empty() {
502-
return Some(name);
496+
if let Some(child) = struct_decl.child(i) {
497+
if child.kind() == "struct_declarator" {
498+
// struct_declarator > pointer_declarator > identifier
499+
// or struct_declarator > identifier (no pointer)
500+
let name = unwrap_property_declarator(&child, source);
501+
if !name.is_empty() {
502+
return Some(name);
503+
}
503504
}
504505
}
505506
}

0 commit comments

Comments
 (0)