Repository navigation
Conversation
/** @type {() => Undefined} */ mark: null was accepted (a literal null or undefined under @type was a placeholder standing for T), so hooks.mark() passed and threw at run time. The initialiser is now checked against the annotation as a const's is, in both the synthesis and the checking path of an object literal: a field that starts as null is declared T | Null. undefined and other values, and the inline /*: T */ form, already were. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LCVsbkjtuBnPMGXCE1qJjr
Rosaclef at ff8f065: about 20 errors in modules that are fine, e.g.
"Property 'bank' not found in type Boolean" at keyboard.js's
`if (pr && pr.bank === 128)`. The failed module's names are typed Error,
and Error unified with anything without binding a variable it met: in
`coll ? <Error> : undefined` the sum's value stayed a free `a`, and
`pr && pr.bank === 128` (with a side unknown, both sides of && must
agree) made it a Boolean, which every later use was checked against.
A variable met by Error now becomes Error (inside a structure too; a
row's tail is left alone), and so does what a constraint on an Error
receiver would have found out (an element, a field), an index into an
Error value, and an object literal spreading one (which said "expected
'{}', found '<error>'"). The trade-off: code that mixes a value from a
failed module with others is checked less until that module is fixed,
which is what Error already meant for member reads and calls.
The unit test that pinned the old rule ("should not bind the var to
Error") now pins the new one; a module test reproduces the Rosaclef
shapes with a two-module program.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LCVsbkjtuBnPMGXCE1qJjr
The get-or-create idiom every Map.get meets since #110, let x = m.get(k); if (!x) { x = []; m.set(k, x); } x.push(1); and the exec loop now that exec returns String[] | Null, while (m) { ...m[1]...; m = re.exec(s); } were rejected: only stable bindings are narrowed. Both write their binding exactly once after its initialiser, which gives an argument as short as the stable one: such a binding holds its first value until the write runs, and a value of the write's expression every time after. The resolver records, per binding, its one write when that is a plain x = e in the declaring function (not from a closure) and the binding is otherwise stable (Resolution::sole_write_at). Then: - after the statement x = e;, x is what every value of e's type is (truthy / not null / not undefined), from its own type; - after if (c) S without else, the write one of S's own statements and S not always exiting, x is c's false fact or that; - a while body up to its write sees the test's true facts, for a binding no closure mentions. A store into the binding is checked at its own type, not a narrowed one. Hoisted function declarations are checked before the statements around them and never see these narrowings. Tests cover the idioms Rosaclef worked around and the shapes that must stay rejected (a hoisted reader, break out of the branch, a second write, a write from a closure, a closure in the exec loop). Not done (3b): a property tested and read again (if (o.f) o.f()). A getter can give a function to the test and null to the call, and a record type doesn't say which fields are getters, so it can't be made sound; documented in type-system.md and flow-narrowing-safe.md. The Lean model narrows only by unwrap of a value bound once; this extension is listed in lean/GAPS.md with why. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LCVsbkjtuBnPMGXCE1qJjr
A soundness audit of the previous commit found:
- What a write's value is known to be didn't look through a named type:
x = nxt() with nxt() => L, type L = Null | {v, next: L}, was taken to
rule out null, so x.v was accepted. value_narrowing now unrolls a
non-nominal named type through its arms, and says nothing for one that
doesn't unfold or for a type not known yet.
- A function declaration is hoisted, so it can run before the write; it
only relied on being checked before the statements around it. It is
now checked with what is known of written (non-stable) bindings
dropped (hoisted_env), whatever statement inference reaches it after.
Regression tests for both, and for a write inside try with a catch and a
switch case entered directly (already rejected).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LCVsbkjtuBnPMGXCE1qJjr
prop_move_data_decl_after_user failed in a PROPTEST_CASES=10000 soak (on
main too): when the function using the decl is the program's last
statement, moving the decl after it makes the decl last, which changes
the program's completion type the oracle compares ("14" vs
"Undefined"). The oracle says such transforms should exclude
themselves; this one now skips that case. The shrunk case is kept in the
regression file.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LCVsbkjtuBnPMGXCE1qJjr
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes found while moving Rosadore (Rosaclef) from 5d0ab98 to 276dd1f.
1. A
@typefield acceptednull(soundness)/** @type {() => Undefined} */ mark: nullwas accepted, because under@typea literalnullinitialiser was treated as a placeholder standing forT. As a result,hooks.mark()passed the check and threw at run time. The initialiser is now checked against the annotation the same way aconst's is, in both the synthesis and the checking path of an object literal. A field that starts asnullis declaredT | Null.undefined, other values and the inline/*: T */form were already checked. The htmx-shaped fixture, the playground example,docs/jsdoc-at-type.mdanddocs/type-system.mdare updated to the new rule.2. An error in an imported module showed up in its importer
Names from a failed module are typed
Error. When a type variable was unified withError, it was left unbound:coll ? <Error> : undefinedgaveUndefined | a. The first use then fixeda: inpr && pr.bank === 128, inty makes both sides of&&agree when one is unknown, which madeaaBoolean. That produced reports like "Property 'bank' not found in type Boolean" in correct code.Now a type variable unified with
ErrorbecomesError, including inside a structure. The same holds for what a constraint on anErrorreceiver would find (an element, a field), for indexing anErrorvalue, and for an object literal that spreads one. EveryErroris produced together with a reported error, so a program that contains one is still rejected. The cost is fewer follow-on errors reported in importers until the failed module is fixed. On Rosadore ff8f065, only the real errors remain.3a. Narrowing a binding written once
This extends the stable-only narrowing design (
docs/flow-narrowing-safe.md, "Extension: bindings written once"). The rule covers alet, parameter, orvardeclared once that is written exactly once after its initialiser, by a plainx = ein its own function. Such a binding holds its first value until that write runs, and a value ofeevery time after. Concretely:x = e;:xis narrowed to what every value ofe's type is (truthy, notnull, notundefined).if (c) { …; x = e; … }with noelse:xis narrowed to whatc's false branch says, or what the write says. The write must be one of the branch's own statements.whilebody, up to its write:xkeeps the test's true facts, as long as no closure mentionsx.This makes the get-or-create idiom and the
execloop type-check. Tests keep these rejected:breakout of the branch before the write;execloop;trywith acatch;switchcase entered directly;null.The Lean model has no narrowing of a written binding (its
unwrapnarrows a value bound once). The difference is listed inlean/GAPS.mdwith the reason.3b. Not done:
if (o.f) o.f()This can't be made sound. A getter can return a function to the test and
nullto the call, and a record type doesn't say which fields are getters. Copying the field into aconststays the way to write it; this is documented indocs/type-system.mdanddocs/flow-narrowing-safe.md.Testing
cargo test --workspace --release --no-fail-fast -- --skip parser::proptests: 1149 passed, 0 failed.tests/rosaclef_regressions.rs,tests/jsdoc_at_type.rs,modules.rsandinfer/tests.rs.web/check.sh): all checks passed, 100 files.Generated by Claude Code