SC9001 ICE: varRef type object != binding dyn on bundled circular module-level consts

Abierto
#4,405 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
52/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, node.js, typescript

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
TypeScript
Estrellas
6.7k
Forks
229
Merge medio
14 h 29 min
PR fusionados (30 d)
787

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de vercel-labs/scriptc

Todos los issues de vercel-labs/scriptc

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.