Commit e950dbc
#135 slice 7 — root cause was NOT empty-array literals (those compile).
It was a fundamental let-polymorphism bug: `check_fn_decl` never
registered a function's explicit `<T>` type parameters, so an uppercase
param `x: T` lowered via `lower_type_expr`'s `TyCon` fallthrough to a
*rigid* `TCon "T"`. `generalize` ignores `TCon`, so every generic
top-level function got `sc_tyvars = []` — effectively monomorphic.
The first call pinned `T`; any second instantiation (or the very first
against a concrete arg) failed `Unify.TypeMismatch (T, Int)`, and
`use prelude::{…}` import-checks failed transitively (result/option/…).
Fix (mirrors the existing let-generalization discipline): in
`check_fn_decl`, before lowering, `enter_level` and register each
`fd_type_params` name in `ctx.type_env` as a fresh tyvar at the deeper
level; `exit_level` before the existing `generalize`, so those vars
(level > ctx.level) become the scheme's quantified `sc_tyvars`. Scoped
save/restore of `type_env` so params don't leak. Applied to both the
extern and normal branches.
Also fixes genuine stdlib bugs surfaced once typecheck passed:
prelude.affine `map`/`filter`/`range`/`repeat`/`fold` reassigned
immutable `let` bindings (`result`/`i`/`acc`) → `let mut`. With both,
**prelude.affine now compiles end-to-end** (resolve→typecheck→codegen).
Verification: `id<T>` instantiated at Int+Bool, generic `fold` from a
monomorphic Int `sum`, monomorphic fns — all compile; the fundamental
change regressed **none** of the suite. 2 regression tests; full suite
green (230). Unblocks the typecheck wall for prelude (and, once
visibility/slice 8 lands, result/option/collections via `use prelude`).
Advances #135. Refs #128, #135.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 289b298 commit e950dbc
3 files changed
Lines changed: 55 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1312 | 1312 | | |
1313 | 1313 | | |
1314 | 1314 | | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
1315 | 1337 | | |
1316 | 1338 | | |
1317 | 1339 | | |
| |||
1340 | 1362 | | |
1341 | 1363 | | |
1342 | 1364 | | |
| 1365 | + | |
1343 | 1366 | | |
1344 | 1367 | | |
| 1368 | + | |
1345 | 1369 | | |
1346 | 1370 | | |
1347 | 1371 | | |
| |||
1396 | 1420 | | |
1397 | 1421 | | |
1398 | 1422 | | |
1399 | | - | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
1400 | 1427 | | |
1401 | 1428 | | |
| 1429 | + | |
1402 | 1430 | | |
1403 | 1431 | | |
1404 | 1432 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
125 | | - | |
| 124 | + | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
135 | | - | |
| 134 | + | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3363 | 3363 | | |
3364 | 3364 | | |
3365 | 3365 | | |
| 3366 | + | |
| 3367 | + | |
| 3368 | + | |
| 3369 | + | |
| 3370 | + | |
| 3371 | + | |
| 3372 | + | |
| 3373 | + | |
| 3374 | + | |
| 3375 | + | |
| 3376 | + | |
| 3377 | + | |
| 3378 | + | |
| 3379 | + | |
| 3380 | + | |
| 3381 | + | |
| 3382 | + | |
3366 | 3383 | | |
3367 | 3384 | | |
3368 | 3385 | | |
| |||
3418 | 3435 | | |
3419 | 3436 | | |
3420 | 3437 | | |
| 3438 | + | |
| 3439 | + | |
3421 | 3440 | | |
3422 | 3441 | | |
3423 | 3442 | | |
| |||
0 commit comments