A generic class instantiated with two types reads the second instance as the first, natively (regressed in 0.4.16)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 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 分钟
- 30 天内合并 PR
- 787
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
vercel-labs/scriptc 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 58/100
vercel-labs/scriptc#4865 ·
维护者通常 1 天内回复
-
Windows ARM64 as a cross-compile target可能已有人在做 @hum-n 于 1 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
vercel-labs/scriptc#4858 ·
维护者通常 1 天内回复
-
post-merge-bisect-unresolved
难度 3/5 1-2 天 新手友好度 43/100
vercel-labs/scriptc#4791 ·
维护者通常 1 天内回复
-
post-merge-bisect-unconfirmed
难度 5/5 一周以上 新手友好度 12/100
vercel-labs/scriptc#4755 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
vercel-labs/scriptc#4634 ·
维护者通常 1 天内回复
查看 vercel-labs/scriptc 的全部 Issue
相似的 Issue
-
bug data-types
难度 2/5 1-3 小时 新手友好度 88/100
ClickHouse/clickhouse-js#1293 ·
维护者通常 1 天内回复
-
area: middleware enhancement good first issue
难度 2/5 1-3 小时 新手友好度 68/100
-
agent/quality testing
难度 1/5 1 小时以内 新手友好度 95/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 92/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
juspay/agent-distro#203 ·
维护者通常 1 天内回复