SC2003 'string | undefined' when a method returning an element of its array field is used inline
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 30/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- compilers
調査の方向性
Reproduce first: save the snippet as repro.ts and run scriptc build repro.ts; the rejection is emitted by the SC2003 union-conversion layout check. Locate where that diagnostic fires and how an inline method-call result reaches it differently than a const-bound value; the const and plain-function variants that already compile are the contrast. Read the #2319 fix for "string concatenation with possibly missing reads" as prior art. Done means the repro compiles and prints 2 with a regression test guarding it.
索引モデルが issue の本文から書いたものです。
説明
A class method declared to return string returns an element of its own string[] field. Using the call result inline, as in obj.last().length, is rejected with SC2003 got 'string | undefined'. Binding the result to a const first compiles.
Reproduction
class Args {
list: string[] = ["a", "bc"];
last(): string {
return this.list[this.list.length - 1];
}
}
console.log(new Args().last().length);
$ node repro.ts
2
$ scriptc build repro.ts -o repro
repro.ts:7:13 - error SC2003: union conversion has no unambiguous layout mapping: expected 'string', got 'string | undefined' (each source arm needs an identical destination arm, a unique compatible record/array layout, or a shared literal discriminant selecting compatible layouts)
It fails 3 out of 3 builds.
What matters
| variant | result |
|---|---|
| repro as above | SC2003 |
const value = new Args().last(); console.log(value.length); |
compiles, prints 2 |
same body as a plain function last(list: string[]): string, used inline |
compiles, prints 2 |
plain function reading the array from a Map, with undefined/empty guards, used inline |
compiles |
So it needs both a method that returns an element read and an inline use of the call result. At the call site the declared return type is string, and there's no union in the source. The limitations page (array-bounds-and-runtime-errors) says a missing element that reaches storage that can't hold undefined throws a TypeError at run time. A build-time rejection that disappears once the value goes through a const looks inconsistent with that.
Possibly related
#2141 (fixed by #2319, after 0.4.5) has the same shape: an inline call result, a body that reads an array element, and binding to a variable avoids it. Its trigger was string concatenation ("x-" + PAD[i]), and the fix describes "string concatenation with possibly missing reads". This repro has no concatenation, and no release after #2319 exists yet, so I couldn't check whether it's covered.
Versions
- scriptc 0.0.36: compiles and prints
2. - 0.1.1, the next version published to npm: SC2003.
- 0.4.5: still SC2003.
SCRIPTC_CHECKER=tsgogives the same result.
Where it came from
A CLI argument parser, args.value("as", "").length > 0. value() returns the last element of a string[] or a fallback. This compiled with 0.0.36 and blocks upgrading to 0.4.5.
Environment
- scriptc 0.4.5 (
@scriptc/cli-darwin-arm64) - macOS 26 arm64
- Node v24.16.0 as the reference
- 主要言語
- TypeScript
- スター
- 6.4k
- フォーク
- 201
- 平均マージ
- 6時間 56分
- マージ済み PR(30日)
- 916
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
vercel-labs/scriptc のほかの issue
-
util.format %o passes the wrong showHidden flag to custom inspectors対応中かも @MathurAditya724 が 1 日前に担当しました。 オープン
難易度 4/5 1〜2日 初心者へのやさしさ 35/100
vercel-labs/scriptc#2571 ·
メンテナーはふだん 1 日以内に返信
-
process.cwd.name keeps the main-thread name inside Workers対応中かも @MathurAditya724 が 1 日前に担当しました。 オープン
難易度 4/5 1〜2日 初心者へのやさしさ 35/100
vercel-labs/scriptc#2557 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
vercel-labs/scriptc#2399 ·
メンテナーはふだん 1 日以内に返信
-
Large LLVM metadata tables crash compilation with a stack overflow対応中かも @MathurAditya724 が 3 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 22/100
vercel-labs/scriptc#2394 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
vercel-labs/scriptc#2209 ·
メンテナーはふだん 1 日以内に返信
vercel-labs/scriptc の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
Automattic/data-liberation-agent#1115 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
CSS enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
pychess/pychess-variants#2448 ·
メンテナーはふだん 1 日以内に返信
-
[architect] Stale planning/scratch files at repo root (COMPONENT_SPLIT_SUMMARY.md etc.) describe already-completed work対応中かも @hivecommons-hive が今日担当しました。 オープンagent/architect architecture help wanted stage/040-covered-by-pr tech-debt
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
kubestellar/console#24716 ·
メンテナーはふだん 1 日以内に返信
-
helm-knative-apply.sh fails with Helm 4対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンarea: triage theme: undefined
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
jhipster/generator-jhipster#35895 ·
メンテナーはふだん 1 日以内に返信