A generic class instantiated with two types reads the second instance as the first, natively (regressed in 0.4.16)

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

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
node.js, typescript
領域
compilers

調査の方向性

Start by reproducing the failure from the issue’s gm6.js example with allowJs, checkJs, and strict enabled; compare native output with the Node.js and scriptc 0.4.12 results. The issue points to packages/light/native/probes/p-g4-generic-composition.js as another reproducer. Trace how the compiler handles the two Lazy specializations and confirm the fix by getting both examples to print 42 ab without diagnostics.

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

説明

A generic class instantiated with a number and then with a string miscompiles the second instance natively, with no diagnostic. It builds 100% static and throws at run time. It regressed between 0.4.12 and 0.4.16 and is still in 0.5.0.

Reproduction

gm6.js, built with a tsconfig that has allowJs, checkJs and strict (so the JSDoc types reach the compiler):

/** @template T */
class Lazy {
  /** @param {() => T} fn */
  constructor(fn) {
    this._fn = fn;
    /** @type {T} */
    this._value = fn();
  }
  /** @param {T} value */
  _assign(value) {
    this._value = value;
  }
  /** @returns {T} */
  get value() {
    this._assign(this._fn());
    return this._value;
  }
}
const n = new Lazy(() => 42);
const s = new Lazy(() => "ab");
console.log(n.value, s.value);
Build Output Exit
Node.js v25.3.0 42 ab 0
scriptc 0.4.12 no diagnostics 42 ab 0
scriptc 0.4.16 no diagnostics Uncaught TypeError: expected number at $, got string 1
scriptc 0.5.0 no diagnostics Uncaught TypeError: expected number at $, got string 1

Without checkJs all three releases print 42 ab. The two instantiations of Lazy seem to share one specialization, so the string instance is read as a number.

Environment

Linux x86_64, glibc 2.39, scriptc's linux-x64-gnu packages from npm.

Found through light's probe packages/light/native/probes/p-g4-generic-composition.js, which fails the same way.

主要言語
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 を短くまとめたダイジェスト。