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

Abierto
#3,996 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
55/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
typescript
Área
compilers

Línea de trabajo

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.

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

Descripción

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