Skip to content

bun check: fix 378 more differences from tsc - #44711

Merged
Jarred-Sumner merged 5 commits into
claude/bun-check-batch5from
claude/bun-check-batch6
Oct 7, 2026
Merged

Jarred-Sumner merged 5 commits into
claude/bun-check-batch5from
claude/bun-check-batch6

Conversation

@Jarred-Sumner

@Jarred-Sumner Jarred-Sumner commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #44685, and stacked on its branch. Fixes 378 more small programs on which bun check and tsc 7.0.2 reported different things.

Missed errors

A default in a pattern whose value is a spread:

declare let y: { a: string };
const { a = 1 } = { ...y, a: 2 };
const n: number = a; // TS2322: Type 'string | 1 | 2' is not assignable to type 'number'

Class members with computed numeric names:

declare const k: number;
class C {
  [k] = 1;
  [+1] = "s";
}
const r: number = new C()[7]; // TS2322: Type 'string | number' is not assignable to type 'number'
new C()[7] = "x";             // was TS2322, not reported by tsc

An accessor in checked JavaScript that the constructor assigns to:

class C {
  constructor() {
    this.a = 1;
  }
  /** @returns {number} */
  get a() {
    return 1;
  }
  /** @param {string | number} v */
  set a(v) {}
}
new C().a = "s"; // TS2322

A property added to a function through a constant key:

const k = "a";
const f: { (): void; a: string[] } = () => {};
f[k] = []; // TS7008: Member 'f[k]' implicitly has an 'any[]' type

After another error

Most of the 378 are programs that already have one error, where what follows differed.

const o = 1;
const v = "";
namespace N {
  export { v as o };   // TS1194, TS2661
  const t: number = o; // TS2322. `o` is the string here
  const u: string = o; // was TS2322
}
declare let y: { a: string };
const o = { ...y, a?() {} }; // TS1162
const n: number = o;         // TS2322 names '{ a: string | (() => void); }', was '{ a?(): void; }'
let a: number;
({ a = 1 } ||= { b: 2 }); // TS2364, and TS2353 for `b`, which was missing

How it was verified

TypeScript's own tests, errors 13,101 of 13,101, byte for byte
TypeScript's own tests, types 12,463 of 12,463
TypeScript's own tests, symbols 12,463 of 12,463
TypeScript's own tests, declaration files 13,032 of 13,032
Small programs that once differed, run through both tools in CI 2,298, 367 of them new
The same programs on a case-sensitive volume 2,298 the same
The new programs in a debug build 366 of 367 the same, the other one is too deep for its stack and skipped there
708 variations of the fixed programs that no fix was aimed at 642 the same, 276 before
tsconfigs of 70 open source projects with the same errors as tsc 636 of 637
tsconfigs with project references, same lines in the same order as tsc -b 316 of 317
Inferred types of local variables in 47 open source projects, as both tools print them 113,371 compared, no new difference
56 open source projects checked with the files cut into tasks in 8 different ways same output as before this PR
Instructions executed on 9 projects (VS Code, mikro-orm, next.js twice, storybook, nuxt, playwright, xstate, drizzle-orm), against #44685 between 0.6% and 3.4% more, 1.8% more on average

Every fix has its program in test/cli/check/differential-cases.json. The test runs tsc and bun check on each and compares the whole output.

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]
Comment thread src/sema/check/flow.rs Resolved
Comment thread src/sema/check/errors_unused.rs Resolved
Comment thread src/sema/program.rs
{
state.seen.insert(path);
for (path, is_lib) in found {
if state.seen.insert(path) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 (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.

Comment thread src/sema/check/print.rs Resolved
Comment thread src/sema/config.rs
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 (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.

Comment thread src/js_parser/sema/lower.rs Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-import import d from "./a" with export = 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 the deep/build flag 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-import export = program and the module.exports = exports.a program 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]
@Jarred-Sumner Jarred-Sumner changed the title bun check: fix 376 more differences from tsc bun check: fix 378 more differences from tsc Oct 7, 2026
@Jarred-Sumner Jarred-Sumner changed the title bun check: fix 378 more differences from tsc bun check: fix 378 more differences from tsc Oct 7, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Still open from earlier reviews (2):

  • Unresolved: 2 minor or pre-existing.

Comment on lines +2792 to +2794
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'.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@Jarred-Sumner
Jarred-Sumner merged commit f0d56cd into claude/bun-check-batch5 Oct 7, 2026
10 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the claude/bun-check-batch6 branch October 7, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant