refactor(objc): use if let Some in for-loop instead of ?#1156
Conversation
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
|
Claude finished @carlos-alm's task —— View job Code Review AnalysisI'm reviewing this PR that refactors Objective-C extractor code to use Todo List:
Root Cause AnalysisProblem Being Solved: The Why This Approach: This change aligns with the established pattern used consistently across all other extractors in the codebase. I verified that:
Risk Assessment: Very low risk. This is a defensive coding improvement with no behavioral change in practice. Technical AnalysisThe change is technically sound: Before (objc.rs:496): for i in 0..struct_decl.child_count() {
let child = struct_decl.child(i)?; // ❌ Short-circuits function on None
if child.kind() == "struct_declarator" {
// ...
}
}After (objc.rs:496-506): for i in 0..struct_decl.child_count() {
if let Some(child) = struct_decl.child(i) { // ✅ Continues loop on None
if child.kind() == "struct_declarator" {
// ...
}
}
}This matches the pattern used throughout the codebase and is more explicit about the intent. Backlog Compliance
Critical ConcernsNone. This is a textbook defensive coding improvement. Final Recommendation
|
Greptile SummaryThis PR fixes a subtle control-flow issue in
Confidence Score: 5/5Safe to merge — the change narrows an overly-broad early-return to the loop iteration where it belongs, with no functional impact on the happy path. The only changed code is the substitution of No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[extract_property_name] --> B[find_child struct_declaration]
B -->|None| C[return None]
B -->|Some| D["for i in 0..child_count()"]
D --> E["struct_decl.child(i)"]
E -->|None| F[skip iteration]
F --> D
E -->|Some child| G{kind == struct_declarator?}
G -->|No| D
G -->|Yes| H[unwrap_property_declarator]
H -->|non-empty| I[return Some name]
H -->|empty| D
D -->|exhausted| J[return None]
Reviews (3): Last reviewed commit: "Merge branch 'main' into fix/1116-objc-i..." | Re-trigger Greptile |
Codegraph Impact Analysis1 functions changed → 3 callers affected across 1 files
|
Summary
let child = struct_decl.child(i)?;inside thefor i in 0..struct_decl.child_count()loop inextract_property_namewithif let Some(child) = struct_decl.child(i).?operator short-circuits the entire enclosing function on the firstNone, not just the current loop iteration. In practicenode.child(i)returnsSomefor everyi < child_count(), so this is harmless today, butif let Someis more defensively correct and matches the pattern already used in the Verilog extractor after refactor(verilog): use if let Some in for-loops instead of ? #1155.if let Some(child) = ...overnode.child(i)?in Verilog extractor for-loops #1116.objc.rswas the only remaining occurrence of the anti-pattern incrates/codegraph-core/src/extractors/(verified viagrep -rnE "for\s+\w+\s+in\s+0\.\." crates/codegraph-core/src/extractors/followed by checking each loop body).Test plan
Closes #1116