Repository navigation
bun check: fix 378 more differences from tsc - #44711
Conversation
Small programs on which `bun check` and `tsc` 7.0.2 reported different things: missed errors, false errors, other wording, other positions. Most of them already have one error, and what follows it differed. Each has its program in test/cli/check/differential-cases.json (2,294, 363 of them new). The tests run both tools on each and compare the whole output. [skip size check]
One of the new programs has a directory named `w*d`. Creating it failed on Windows, and with it every program of that part of the test. [skip size check]
| { | ||
| state.seen.insert(path); | ||
| for (path, is_lib) in found { | ||
| if state.seen.insert(path) { |
There was a problem hiding this comment.
🟡 (optional) Projects with several copies of the same package version now read and parse every copy, where the base read only the first. The prefetch at src/sema/program.rs:5258 queues each path that has not been seen, and src/sema/program.rs:4181 marks every file readable; the base skipped a file whose package id a read file already had. Fix: keep the duplicate-copy skip in the prefetch and in is_read using the package_id that Resolution and Loaded::references now carry, while keeping the late re-queue at src/sema/program.rs:4657 that reads a copy that turns out to be the kept one. The PR's instruction counts call this an accepted cost; the cost scales with the duplicate count in node_modules, which those 9 projects do not bound. [also at: src/sema/program.rs:5253 - Users of pnpm or nested-node_modules monorepos get a slower bun check after merging: every physical copy of a same-version package file is now read, parsed and has its imports resolved, where the base read one copy per package id.; src/sema/program.rs:4181 - Users running bun check on pnpm or nested-node_modules monorepos now pay to read, parse and resolve imports for every physical copy of each package file, where the base read one copy per package id. program.rs:4181 sets is_read: first == id and the former seen_packages pre-read dedupe is gone, so duplicates are only dropped later in collectFiles after their parse.]
Why this was flagged
Trigger: a node_modules tree with N copies of one package at the same version, reached by bun check through Files::load. Base: src/sema/program.rs base lines 3895-3906 set is_read false for every copy after the first with that package id, and base lines 4925-4931 (seen_packages) kept the prefetch from queuing such a copy, so only one copy's .d.ts files were read and parsed unless it turned out to be the kept one. After the change: is_read: first == id at src/sema/program.rs:4181 is true for every copy, seeds at src/sema/program.rs:4352 includes all of them, and load_ahead at src/sema/program.rs:5258 queues every unseen path, so all N copies are read and parsed by load_one before collectFiles at src/sema/program.rs:4643 discards N-1 of them. Users with heavily duplicated dependency trees pay N times the parse work for those packages; nothing bounds it.
Verification: Triggers whenever a node_modules tree contains more than one copy of the same package version reachable by bun check; the base read only the first copy, the head reads and parses every copy. Head src/sema/program.rs:4181 is now just is_read: first == id,. Head lines 5257-5261 queue every path not yet in seen.
| if usage != Usage::Exclude && parts.last() == Some(&&b"**"[..]) { | ||
| return None; | ||
| } | ||
| // No path part has a `/` in it, so nothing matches below `//server` or `http://host`. | ||
| let root = parts[0]; | ||
| parts[0] = root.strip_suffix(b"/").unwrap_or(root); |
There was a problem hiding this comment.
🟡 (optional) Users whose project path begins with // on Linux or macOS now get no input files from include globs, where the base matched them. config.rs:1030 builds the glob from get_path_components, which keeps //server as one root component (resolve.rs:1218), and :1036 only strips its trailing slash. The candidate files are split by path_parts (config.rs:1014-1018), which yields "" then home, so the first literal never equals and every include is rejected. The base split both sides the same way. Fix: derive glob components and candidate components from the same function (use get_path_components in path_parts too) so UNC-style roots compare equal on every platform.
Why this was flagged
Trigger: a tsconfig or project directory whose absolute path starts with two slashes on a POSIX system, e.g. bun check -p //home/u/proj/tsconfig.json or a cwd that bash reports as //home/... (POSIX permits a leading // and shells preserve it). join() at resolve.rs:1293-1301 deliberately keeps…
Verification: nit (acknowledged in diff at src/sema/config.rs:1034). Trigger: a project path with a leading // on Linux/macOS. config.rs:1036 only strips the trailing slash, leaving Component::Literal("//home"); path_parts (config.rs:1014-1018) emits "" then home, so match_parts returns false and the project ends up with no input files. On the base the parts matched path_parts exactly, so this is a regression.
There was a problem hiding this comment.
Beyond the inline findings, I also looked at the new TLessThanSlash token in src/js_parser/lexer.rs — it is gated on is_jsx, which only the type checker sets, so the bundler's lexer output is unchanged — and at the removal of the swallowed speculative-parse counter, where the parseErrorAtRange dedup now runs directly on prev_error_loc (carried through EscapedWord for keywords that are re-taken) and I could not construct a lookahead that loses an error the base kept.
Extended reasoning...
The change is a 95-file, +12.7k/-5k batch across the tolerant lexer, parser, HIR lowering, binder, module resolution and most checker error modules of bun check, with 363 new differential cases; it touches no auth, crypto or injection surface. Seven findings are posted inline and the hunt stopped at its bug cap, so a human should review; this note only records what else was examined and ruled out.
Findings marked 🟡 are optional suggestions and need no follow-up push.
Additional findings (outside the current diff — GitHub can't attach inline comments there):
-
🔴
test/cli/check/differential-cases.json:1377— Maintainers lose two tsc-parity regression checks: the cases "08-C11a" and "32-C18b" are deleted outright, with no replacement and no reason in the PR text. Every other removed key is only moved, but the a.ts of "08-C11a" (self-importimport d from "./a"withexport = v) and the m.js of "32-C18b" (module.exports = exports.a;) appear nowhere in the new file. Deleting a differential case is exactly how a new divergence from tsc gets hidden. Fix: restore both cases (adding thedeep/buildflag if they are only slow), or state in the PR why each no longer applies and what covers it instead. [also at: test/cli/check/differential-cases.json:1380 - Two existing differential cases are deleted with no replacement or stated reason, so the self-importexport =program and themodule.exports = exports.aprogram lose tsc-parity coverage after merging.]Why this was flagged
The diff removes the keys "08-C11a" (old file around the "08-C11b" entry, test/cli/check/differential-cases.json) and "32-C18b" (before "32-C19") and does not add them back under any name: a search of the new file for the a.ts text `import d from "./a"; const v = { n: 1, m: d }; export =…
Verification: Verified in
git diff 1381606328ae22603db8cc897dd6afcb108e4e70 HEAD -- test/cli/check/differential-cases.json: hunk@@ -1351,12 +1377,6 @@removes "08-C11a" and hunk@@ -7344,13 +7530,6 @@removes "32-C18b". Neither key nor either file body appears anywhere in the new test/cli/check/differential-cases.json, nor anywhere else under test/.
- A class property named by a string of six bytes that starts with NUL
made the check of property initialization panic. The key of `this[k]`
is a typed value now, not bytes in a name.
- A JSDoc comment with thousands of `@overload` or `@callback` tags in a
row overflowed the stack. The parser asks the stack guard, and stops
nesting for the rest of the comment once the stack has been low.
- `import d from "./a"; const v = { m: d }; export = v;` lost the TS7022
at `export = v`. Every binding of an import statement is resolved at
the statement, as `* as ns` already was.
- `module.exports = exports.a;` got a TS7022 that tsc does not report:
the object of an alias-like expression was evaluated twice.
- A type nested too deeply to be printed whole is elided without the
claim that the check ran out of stack.
- A byte search goes through bun_core::strings.
The two programs above are back in the differential cases.
[skip size check]
bun check: fix 376 more differences from tscbun check: fix 378 more differences from tsc
There was a problem hiding this comment.
Beyond the inline finding, I checked two more things on this push: the new typed AccessKey::Name | Variable(Root) in src/sema/check/flow.rs (lines 17-21) removes the atom-byte decoding, so no string literal can be mistaken for a symbol id in is_assigned_in_constructor; and the import-cycle path through export = obj.prop at src/sema/check/symbols.rs:1130, where returning Unknown when the object type was not cached mirrors tsc's getResolvedSymbolOrNil (it evaluates nothing), so that is not a regression.
Extended reasoning...
The third commit adds a typed property-key enum in flow.rs and a stack guard for nested @ overload/@ callback JSDoc tags in errors_unused.rs, on top of the large parser/binder/checker diff. The symbols.rs alias-resolution change was examined and matches the tsc behavior it cites. The one inline finding (remaining unguarded @ param/@ property recursion) is the only open item from this run.
The latest push brings back an issue flagged in an earlier review; replied in that comment's thread.
Still open from earlier reviews (3):
- 🔴
src/sema/check/errors_unused.rs:1919—A JS/TS file with a long run of @ overload (or @ callback) tags in one JSDoc comment can overflow the checker thread's… - Also unresolved: 2 minor or pre-existing.
If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.
A run of `@param {Object} a` tags nests through another cycle of calls
than `@overload` does, and still overflowed the stack. Every cycle in the
parser goes through one of two functions. Both ask the stack guard now.
The test covers six shapes of tags.
The test of a type that is nested too deeply to be printed compared 60
characters with 61, and expected the wrong summary line. It was skipped in
debug builds, so it first ran in CI. It runs in every build now, with
fewer levels where frames are large.
[skip size check]
… out One program has a directory named with a letter of Unicode 16. APFS on macOS 14 refuses it (EILSEQ), and every program of that part of the test failed with it, on the agents that run that version. Each program is written by itself now, and that error leaves out that program alone. [skip size check]
| const { stdout, stderr, exitCode } = await check(dir, ["--noErrorTruncation"]); | ||
| expect(stdout).toStartWith("a.ts(2,14): error TS2322: Type '{ a: { a: { a: { a: { a: { a: "); | ||
| expect(stdout).toEndWith(" }; }; }' is not assignable to type 'number'."); |
There was a problem hiding this comment.
🟡 nit (optional): maintainers get a regression test that passes whether or not the printer elides the deep type, so it cannot catch the elision path breaking again. At test/cli/check/check.test.ts:2793-2794 the assertions are toStartWith on the outer { a: { a: prefix and toEndWith on }; }; }', both of which hold for the fully printed type and for one whose middle became any. Fix: assert the strongest invariant the test name claims, e.g. that stdout contains /*elided*/ any (ELIDED in src/sema/check/print.rs:57) when the depth is meant to exceed the printing budget, or compare the whole line against tsc's output if no elision is expected at this depth, so the test fails if is_stack_low_for_printing stops firing or fires with a spurious ran-out-of-stack report.
Why this was flagged
The test at test/cli/check/check.test.ts:2784-2797 builds a type nested 1000 levels (100 under isDebug or isASAN) and claims it is "nested too deeply to be printed whole". The only assertions on the message are toStartWith("a.ts(2,14): error TS2322: Type '{ a: { a: { a: { a: { a: { a: ") at…
Verification: nit. Triggering condition: any regression that makes the printer stop eliding (or elide wrongly) a type nested past the 7/8-of-stack threshold while not overflowing the stack passes this test unchanged. Mechanism verified: test/cli/check/check.test.ts:2793-2794 assert only toStartWith and toEndWith; both hold for the fully printed 1000-level type and for an elided one.
Follow-up to #44685, and stacked on its branch. Fixes 378 more small programs on which
bun checkandtsc7.0.2 reported different things.Missed errors
A default in a pattern whose value is a spread:
Class members with computed numeric names:
An accessor in checked JavaScript that the constructor assigns to:
A property added to a function through a constant key:
After another error
Most of the 378 are programs that already have one error, where what follows differed.
How it was verified
tsctsc -bEvery fix has its program in
test/cli/check/differential-cases.json. The test runstscandbun checkon each and compares the whole output.