Commit 2efe0e3
fix(codegen-deno): don't re-declare preamble Option/Result constructors (#606)
## Deno-ESM: stop re-declaring the preamble's Option/Result constructors
The locally-declared sibling of the duplicate-constructor bug fixed in
#604.
### Bug
The Deno-ESM runtime preamble always declares `Some`/`None`/`Ok`/`Err`.
`gen_type_decl` *also* emits them for any program that **declares**
`type Option`/`type Result` — including `stdlib/prelude.affine` — so the
emitted module crashes under node:
```
$ affinescript compile --deno-esm -o prelude.deno.js stdlib/prelude.affine
$ node prelude.deno.js
SyntaxError: Identifier 'Some' has already been declared
```
It stayed latent because the #136 AOT smoke only checks the emitted
module is **non-empty** — it never runs it.
### Fix
Skip the variants the preamble already provides
(`Some`/`None`/`Ok`/`Err`) when lowering a `TyEnum` in
`codegen_deno.ml`. User-defined enums are unaffected.
### Verified
```
stdlib/prelude.affine -> deno : `const Some` ×1, runs under node ✅ (was ×2, crashed)
user enum (Color=Red|Green|Blue): still emitted, runs ✅
tools/run_codegen_deno_tests.sh : all harnesses pass under node ✅
dune test : 459 green (+1 new regression test)
```
New test `Deno-ESM no duplicate Option/Result constructor` asserts
`const Some` is declared exactly once — the run-under-node guard the AOT
smoke lacked.
### Scope / follow-ups
- This + #604 close the duplicate-constructor class on the **Deno**
backend (the one executed in CI).
- The **JS and C** backends show the same latent preamble/declaration
duplication (2 `Some` decls) but their output isn't executed in CI —
tracked as a follow-up, not fixed here.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01Lz7pRcec2Z3tVtaAhvB3M8
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Lz7pRcec2Z3tVtaAhvB3M8)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent c7922cf commit 2efe0e3
2 files changed
Lines changed: 55 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1685 | 1685 | | |
1686 | 1686 | | |
1687 | 1687 | | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
1688 | 1697 | | |
| 1698 | + | |
| 1699 | + | |
1689 | 1700 | | |
1690 | 1701 | | |
1691 | 1702 | | |
| |||
1703 | 1714 | | |
1704 | 1715 | | |
1705 | 1716 | | |
| 1717 | + | |
1706 | 1718 | | |
1707 | 1719 | | |
1708 | 1720 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
228 | 269 | | |
229 | 270 | | |
230 | 271 | | |
231 | | - | |
| 272 | + | |
| 273 | + | |
0 commit comments