SC9001 "missing method function toString" when the entry exports a class whose `toString` nothing calls

Aperta
#3,996 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
compilers

Direzione di ricerca

Start by tracing the compiler path that handles exported classes and the %util.clsString call; the issue also points to the related %dyn.class.protocol report in #3503. Reproduce with the provided index.ts and npx [email protected] build index.ts, then compare the exported class case with the listed variants that compile. Done means the entry compiles without either SC9001 error.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

scriptc 0.4.14 crashes on an entry module that exports a class with its own toString when the program never calls that method.

Reproduction

package.json:

{ "type": "module" }

index.ts:

export class U {
    toString(): string {
        return 'u';
    }
}
npx [email protected] build index.ts

Observed

index.ts:1:1 - error SC9001: internal compiler error: class U: missing method function "toString" — please report this
index.ts:1:1 - error SC9001: internal compiler error: in %util.clsString.5f569930a64f: call to undeclared function "%U.toString" — please report this

2 errors.

The same errors appear with export default class U, with an unexported class returned from an exported factory (export const make = () => new U();), and with --emit obj.

Expected

The module compiles.

These variants compile:

  • The program calls the method: export class U { ... } followed by console.log(new U().toString());.
  • The class is not exported and the entry uses it locally, for example console.log(new U() instanceof U);.
  • The method has another name, such as describe(), or is valueOf().
  • The entry exports an instance: export const u = new U();.
  • Another module imports U and the entry exports nothing from it.

#3503 reported an SC9001 for toString reached through %dyn.class.protocol in 0.4.10. This one goes through %util.clsString and needs no interface.

Context

JSPrismarine hits this when building a package entry on its own: UUID in @jsprismarine/protocol and ServerName in @jsprismarine/raknet export classes like this (https://github.com/JSPrismarine/JSPrismarine/issues/3323).

Environment

  • scriptc 0.4.14 from npm
  • Linux x86_64, glibc 2.43
  • Node.js 26.13.0
Lingua principale
TypeScript
Stelle
6.7k
Fork
229
Merge medio
14h 29m
PR unite (30g)
787

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vercel-labs/scriptc

Tutte le issue di vercel-labs/scriptc

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.