SC9001 ICE: varRef type object != binding dyn on bundled circular module-level consts
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js, typescript
Research direction
Start by reading the compiler’s handling of module-level const bindings, returned closures, and varRef type validation; the issue does not name source files or tests for these paths. Reproduce with the 12-line JavaScript example using scriptc build, then compare it with the controls that compile. Done when the bundled JavaScript builds successfully and its runtime output remains 1.
Written by the indexing model from the issue text.
Description
Summary
scriptc build hits SC9001 (internal compiler error: varRef "…" type object != binding dyn) on legal JavaScript that bundlers emit: a module-level const closes over another module-level const that is initialized later by a factory returning new SomeClass(...).
scriptc coverage of the same file is 100% static. Node runs it. The identical program as TypeScript compiles. So this is a codegen/IR-validation ICE, not a coverage or language-service crash.
Reduced from rolldown-bundled effect/Schema (t3code vp pack chunk Schema-CHz9fEw2.mjs, four ICEs at the Go-nil codec consts nullAsMissing / nullAsEmptyArray / emptyRecord / nullAsEmptyRecord). Please do not ask applications to unminify that chunk by hand — the 12-line program below is sufficient.
Reproduction
repro.mjs:
class Box {
constructor(v) {
this.v = v;
}
}
function apply(f) {
return f;
}
const earlier = apply(() => later);
const make = (v) => new Box(v);
const later = make(1);
console.log(earlier().v);
$ node repro.mjs
1
$ scriptc coverage repro.mjs
# 6/6 statements static (100%)
$ scriptc build repro.mjs -o out
repro.mjs:9:29 - error SC9001: internal compiler error: in %fn.309985bfdfc6: varRef "%g.e.later" type object != binding dyn — please report this
8 | }
9 | const earlier = apply(() => later);
| ^~~~~
10 | const make = (v) => new Box(v);
1 error.
Minified to one line, same ICE:
class Box{constructor(v){this.v=v}}function apply(f){return f}const earlier=apply(ast=>later),make=v=>new Box(v),later=make(1);console.log(earlier(0).v)
apply can be the identity (return f). What matters is that the closing lambda is returned from a call, not assigned directly.
Controls that compile and print 1
Same program as TypeScript (repro.ts with a typed apply / make) — scriptc build succeeds.
Reordering so later is initialized first:
const make = (v) => new Box(v);
const later = make(1);
const earlier = apply(() => later);
Direct new instead of a factory (still a circular const):
const earlier = apply(() => later);
const later = new Box(1);
Unbundled modules (the factory and later in a second file, imported by the closer) also compile. That is why unminified npm effect source (scriptc build entry.mjs --npm-static=effect) succeeds while a rolldown bundle of the same library fails.
Original trigger
scriptc build of a rolldown bundle of [email protected] Schema (pretty-printed, original names kept) reports four ICEs, all this pattern:
Schema.unmin.mjs:12937:39 - error SC9001: … varRef "%g.e.nullAsMissing" type object != binding dyn
Schema.unmin.mjs:12941:144 - error SC9001: … varRef "%g.e.nullAsEmptyArray" type object != binding dyn
Schema.unmin.mjs:12942:139 - error SC9001: … varRef "%g.e.emptyRecord" type object != binding dyn
Schema.unmin.mjs:12942:165 - error SC9001: … varRef "%g.e.nullAsEmptyRecord" type object != binding dyn
Those names are module-level consts in effect/src/internal/schema/toCodec.ts:
const nilAsMissingAtEncoded = applyToSelfOrLastLinkEncoding((ast) => {
return orNull(ast, decodeNull(never, nullAsMissing));
});
const nilAsEmptyAtEncoded = applyToSelfOrLastLinkEncoding((ast) => {
// …
return orNull(ast, decodeNull(replaceChecks(emptyRecord, ast.checks), nullAsEmptyRecord));
});
const nullTo = (decode) => new Transformation(decode, forbidden(() => "…"));
const nullAsMissing = nullTo(transformOptional(() => none()));
const nullAsEmptyArray = nullTo(transform(() => []));
const nullAsEmptyRecord = nullTo(transform(() => ({})));
const emptyRecord = record(string, never);
Circular module-level consts through a helper that only stores the callback are legal JS (const TDZ is not hit because applyToSelfOrLastLinkEncoding does not call f during init). Rolldown concatenates them into one module; scriptc then types the binding as dyn and the varRef as object.
Workaround for consumers
Compile TypeScript / npm source (ordinary per-file modules), not bundler output. t3code will feed scriptc build src/binMain.ts rather than vp pack chunks for this reason. That is a consumer dodge, not a fix.
Environment
- scriptc 0.4.17 and 0.4.16 (identical ICE on the 12-line repro; not a 0.4.17 regression)
@scriptc/cli-linux-x64-gnu, Node.js 24.13.1, linux x64- effect 4.1.5 for the original Schema bundle; the reduced repro has no dependencies
Relationship to existing reports
Searched open and closed SC9001 / ICE issues (varRef, binding dyn, emptyRecord, nullAsMissing, minified circular consts). Closest hits are other SC9001 shapes (recordKeyGet, bytesSet, toString protocol) — none are varRef type object vs binding dyn. Distinct from #4381 (tsc-ts SIGSEGV on one large file) and from #4171 (coverage abort on @effect/platform-node).
- Dominant language
- TypeScript
- Stars
- 6.7k
- Forks
- 229
- Avg merge
- 14h 29m
- Merged PRs (30d)
- 787
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vercel-labs/scriptc
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
vercel-labs/scriptc#4865 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
vercel-labs/scriptc#4864 ·
Maintainers usually reply within 1 day
-
Windows ARM64 as a cross-compile targetPossibly taken @hum-n claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
vercel-labs/scriptc#4858 ·
Maintainers usually reply within 1 day
-
post-merge-bisect-unresolved
Difficulty 3/5 1-2 days Newbie friendliness 43/100
vercel-labs/scriptc#4791 ·
Maintainers usually reply within 1 day
-
post-merge-bisect-unconfirmed
Difficulty 5/5 Over a week Newbie friendliness 12/100
vercel-labs/scriptc#4755 · 1 comment ·
Maintainers usually reply within 1 day
All issues in vercel-labs/scriptc
Similar issues
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-js#1293 ·
Maintainers usually reply within 1 day
-
area: middleware enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
agent/quality testing
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
juspay/agent-distro#203 ·
Maintainers usually reply within 1 day