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

オープン
#3,996 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript
領域
compilers

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
TypeScript
スター
6.7k
フォーク
229
平均マージ
14時間 29分
マージ済み PR(30日)
787

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

vercel-labs/scriptc のほかの issue

vercel-labs/scriptc の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。