Values through a binding: a const read once, a callback by name, Readonly<T> and ?. on a present value read as what they are (523 silent sites to 356) #135
Loading…
Reference in a new issue
No description provided.
Delete branch "values-through-bindings"
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?
Based on
spelling-harness(#134), and contains it: the diff shown is this piece alone.#134 measured where a rule goes silent when the same code is written another way, and fixed what one normalisation of the tree could fix. What it left was on the list with reasons, and four groups were most of it:
In each row a rule that reported the left form was silent on the right one, or reported the right one for nothing.
What this adds
constmissing-mut, by design)x?.m()on a value that is thereReadonly<T>around a parameter's typeA
constread once is its value, as a question rules ask (analyze/values.rs:value_of,function_of), not a rewrite of the tree. The first attempt moved the value to where it is read and broke four things: rules that are about the binding (aResultkept in a local,missing-mut), code that builds spans assuming a node contains its children, messages that then quoted the moved value, and line numbers. The answer is given only where nothing can come between: theconstis read exactly once, in the next statement, evaluated first there, not in a branch, a loop or a nested function. Sothis.items.push(await load())stays different fromconst r = await load(); this.items.push(r), which readsthis.itemsafter the wait.A function passed by name is found the same way. A listener passed by a name nothing else reads cannot be removed either, so
listener-cleanupreports it like the arrow written in place; a function handed by name tounsafe(...)is guarded in its body, which removes 40 of 43 falseunhandled-failurereports.Readonly<T>on a parameter is opened in the normalisation, keeping the written span.Readonly<Mut<T>>is still a loan: TypeScript keeps the brand, andReadonlyonly blocks assigning its fields.x?.m()isx.m()where the file showsxcannot be absent: a parameter or variable whose written type has noundefinedornull(aliases of the file opened; imports, type parameters andunknowncount as "maybe"), or one bound tonew, a literal or a function.Evidence
nullthat only leaves throughJSON.stringify, which the rule already allows when written in place.no-object-dictionaryon parameters typedReadonly<Record<string, V>>and read by a key from data: the rule did not see throughReadonly. All read by the implementer: 13 are what the rule is for, one is a false positive the rule gives the same way withoutReadonly.Resultawaited through aconstand a listener passed by a name used once are now reported like their twins. Correct code stays silent both ways, and where something happens between theconstand its read (a write, anawait, a second call) nothing new is reported.safe-ts emitis byte-identical to the base on the demo, std's tests and files full of these spellings.What turns red on upgrade
Three expectations in this repository's own fixtures changed, each the twin of a form already reported:
const pending = saveAsync(order); await pending;drops theResultexactly asawait saveAsync(order);does:must-use-result.listener-cleanup.Readonly<Record<...>>:no-object-dictionary.What is left
The 126 sites through a
constthat remain are rules that do not ask the question yet. The machinery is there; about 35 rules still match their shape where the value is written. The largest ismust-use-result's kept-Resultanalysis (18), which is a pass of its own. Each line of the list says so.?.on an import, a call's result, a member read, and globals that may really be absent (window,process): 28 sites.const items = this.items; items.push(x)): aliasing, a piece of its own.Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review and acceptance tests) in Claude Code.