fix: Z029 composite-type false negatives + surface silent IO/config errors#7
Conversation
…rrors WHY: A full multi-agent adversarial audit of the fork delta vs upstream (bfcb30d..b212557, 24 raw findings → 3 confirmed after verification) surfaced three real, verified defects present at HEAD: 1. Z029 (redundant @as in struct init) only compared bare-identifier field types, so `@as(*u32, ...)`, `@as(?T, ...)`, `@as([N]T, ...)` and `@as(a.b.C, ...)` on struct fields were silently skipped — genuine linter false negatives (the tool's core job). 2. lintDirectory's `walker.next(io) catch null` ended traversal silently on a permission error / symlink loop, leaving the rest of the tree un-linted with no diagnostic. 3. main's `FileConfig.load(...) catch .{}` swallowed config-discovery errors (e.g. an allocation failure joining the search path) without logging. All three are pre-existing upstream but ship in the fork; this cycle's scope was the whole fork-vs-upstream delta. WHAT: - Linter.zig: findContainerFieldTypeInTree now returns the field type's raw source (Ast.getNodeSource) instead of only `.identifier`. Added getAsTypeText (source of an `@as` cast's type node) and typeTextEql (whitespace-insensitive compare). checkRedundantAsInStructInit compares source text, so all composite field types are handled. getAsTypeName is retained (still used by call-arg / array / return / value paths). - main.zig: directory-walk errors now print a warning before stopping; config load logs the error before falling back to defaults. Both Z026-clean. - Added 4 Z029 regression tests (pointer/optional/array detection + a different-pointer-type negative case). IMPACT: src/Linter.zig, src/main.zig. No behavior change for the previously handled identifier case; new detections are strict (whitespace-normalized exact type-text match, so different types still don't trigger). Linter now catches a class of redundant casts it previously missed and no longer fails silently on unreadable directories/config. VALIDATION: TDD — the 3 composite-type tests failed (expected 1, found 0) before the fix and pass after. `zig build test --summary all` => 7/7 steps, 281/281 tests pass, zig fmt clean, self-lint (run exe ziglint) clean. The self-lint gate also caught an empty `catch {}` in the first draft of fix #2 (Z026), which was corrected to `try`.
|
Warning Review limit reached
More reviews will be available in 50 minutes and 13 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. Review infoRun configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Run ID: Files selected for processing (2)
Finishing TouchesGenerate unit tests (beta)
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e73870843c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| while (ia < a.len and std.ascii.isWhitespace(a[ia])) ia += 1; | ||
| while (ib < b.len and std.ascii.isWhitespace(b[ib])) ib += 1; |
There was a problem hiding this comment.
Avoid concatenating type tokens when normalizing
When the field type contains whitespace that separates tokens, this byte-level normalization can turn a different type into the same text. For example, a field declared as *const u8 and a cast written as @as(*constu8, ...) become identical after stripping spaces if the user has a constu8 type alias, so Z029 reports the cast as redundant even though the cast type is not the field's context type. Normalize trivia without merging tokens, or compare the parsed type structure instead of deleting all whitespace.
Useful? React with 👍 / 👎.
Code Review Roast 🔥Verdict: 1 Issue Found | Recommendation: Consider before merge Overview
Issue Details (click to expand)
🏆 Best part: Finally catching redundant 💀 Worst part: The 📊 Overall: Like a double-shot espresso — hits the target but might keep you up at night worrying about false positives. Files Reviewed (2 files)
Reviewed by laguna-m.1-20260312:free · Input: 491K · Output: 5.7K · Cached: 284K |
Summary
A full multi-agent adversarial audit of the entire fork delta vs upstream (
bfcb30d..b212557, 882+/465-, 20 files) ran 5 review dimensions → adversarial verification of every finding. 24 raw findings → 3 confirmed, 21 refuted. This PR fixes the 3 confirmed defects (all real and present at HEAD; pre-existing upstream but in the fork's shipped code).🟠 #1 — Z029 false negatives on composite field types (high)
findContainerFieldTypeInTree(Linter.zig) only stringified.identifierfield types, so redundant@ason pointer / optional / array / field-access struct fields was silently skipped:Fix: compare the raw source text of the field type and the
@ascast type (Ast.getNodeSource), whitespace-normalized (typeTextEql). Handles all composite types uniformly.getAsTypeNameis retained for the other Z029 paths (call args, array init, return, value).🟡 #2 — Silent directory-walk failure (medium)
while (walker.next(io) catch null)inlintDirectoryended traversal silently on a permission error / symlink loop, leaving the rest of the tree un-linted with no diagnostic. Fix: print a warning before stopping (Z026-cleantry).🟡 #3 — Silent config-load error (medium)
FileConfig.load(...) catch .{}swallowed config-discovery errors (e.g. an allocation failure joining the search path) without logging. Fix: log the error before falling back to defaults.Tests (TDD)
4 new Z029 regression tests in
Linter.zig. The 3 detection tests (pointer / optional / array) failed withexpected 1, found 0before the fix and pass after; a 4th asserts a different pointer type still does not trigger (no false positive).Validation
(277 prior + 4 new.) Notably, ziglint's own self-lint gate caught an empty
catch {}(Z026) in the first draft of fix #2, which was corrected totry— the tool linting its own fix.Audit notes
The adversarial verifier correctly refuted 21 findings — arena-allocator non-leaks, bounds-checked slices (guarded by
startsWith/findcontracts), thewriter()"reversed params" false alarm,environ_maplifetime, etc. — and excluded real-but-pre-existing-and-untouched issues (e.g. aresolveNodeType ↔ resolveFieldAccessunbounded recursion that exists identically in upstream and is a separate path from the PR #5 alias-depth fix). That recursion is a good candidate for a follow-up (and an upstream PR), but is out of scope here since the fork didn't introduce or touch it.