A generic class instantiated with two types reads the second instance as the first, natively (regressed in 0.4.16)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 58/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- compilers
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- TypeScript
- Stars
- 6.7k
- Forks
- 229
- Avg merge
- 14h 29m
- Merged PRs (30d)
- 787
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vercel-labs/scriptc
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
vercel-labs/scriptc#4865 ·
Maintainers usually reply within 1 day
-
Windows ARM64 as a cross-compile targetPossibly taken @hum-n claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
vercel-labs/scriptc#4858 ·
Maintainers usually reply within 1 day
-
post-merge-bisect-unresolved
Difficulty 3/5 1-2 days Newbie friendliness 43/100
vercel-labs/scriptc#4791 ·
Maintainers usually reply within 1 day
-
post-merge-bisect-unconfirmed
Difficulty 5/5 Over a week Newbie friendliness 12/100
vercel-labs/scriptc#4755 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
vercel-labs/scriptc#4634 ·
Maintainers usually reply within 1 day
All issues in vercel-labs/scriptc
Similar issues
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-js#1293 ·
Maintainers usually reply within 1 day
-
area: middleware enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
agent/quality testing
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
juspay/agent-distro#203 ·
Maintainers usually reply within 1 day