compare-misses-undefined and strict-truthiness follow narrowed paths (and undo them where code may change the path) #153
Loading…
Reference in a new issue
No description provided.
Delete branch "narrowed-paths"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
compare-misses-undefinedandstrict-truthinessreported a value as "may beundefined" when TypeScript had already narrowed it. An adopter's tree had 5 such false positives out of 8compare-misses-undefinederrors. The forms were:b.plots.lengthinsideif (b.plots !== undefined)letnarrowed byroute && route.length === 0const books = b.booksb.books = kept.filter(f); if (b.books.length === 0)if (!b.plots?.some(f)) return;, thenb.plots.filter(...)What changed
narrowed.rs(new): the guard walk thattruthiness.rshad (if/?:/&&/||/ an earlierif (…) return;), plus assignment narrowing. Paths are compared by root and steps (flow::Root), not by text. A test of a longer path counts for its prefixes. The nearest narrowing decides.awaitoryield, when the root is imported, global, declared outside the function, or written or handed on by a function not running here (a closure, another method)awaitoryield, for any member pathforEach,map,filter, …) keep the narrowing, with their whole body counted as code in between.Shapes::ofreads it (Shapes::with_narrowing, onlytruthiness.rsturns it on). Every path read sees it: prefixes, declarator inits, destructured parts (in_pattern_at).shape::defined_at:defined_test, and also says where the test proved it. The region starts after that point, som.get(k)inside its own test doesn't count as a call that undoes it.json_value.rs:Shape::Definedof a declared type keeps the type declared (defined_expr). Before, it converted the whole type, soDefined(world)of a large interface came out unknown and the finding was lost.flow.rsgraph per question. Loops are handled by counting their whole body as part of the region.The docs list what is followed, what undoes it, and what it can't see: aliasing, getters and proxies, and a non-array
.mapthat keeps its callback for later. CHANGELOG has an entry under Unreleased → Fixed.Results
--idiomatic, fast profile):compare-misses-undefined: 8 → 3. I checked the 5 removed ones by hand (invariants ×2, library, rules, social), and all were narrowing false positives. The 3 left are?.chains, which are true reports.strict-truthiness: 236 → 237.undefined" ones, 1 was a false positive: world-ops, a.filteron anOptionfield after a?.someguard. It is now reported as a plainnumber. The other 5 are dictionary or index reads, orfirst?.share, and are true.if (i)on aforEachindex. It was unknown before.cargo nextest run --workspacepasses, 413/413, includingmeaning.rsand the work ceilings (events are collected lazily, once a narrowing is found).npm run test:docspasses.Held-out cases
In
fixtures/compare_misses_undefined/narrowed.tsandfixtures/strict_truthiness/narrowed.ts, plus a message test inmessages.rs. I checked that each left-alone form is reported when its narrowing is taken away.ifand inside||path.push()?.test: exact, and as a prefixcounts[k]and an elementitems[i]letwith&&?.someguardconstinsidesetTimeoutthis.clear())deletei += 1items[j] = …letletwith writes insidesetTimeoutawait🤖 Generated with Claude Code