Repository navigation
Commit c587aa4
feat(diagnostics): prelude-hint for UndefinedVariable / Unbound (stdlib #5)
Closes #415. Stdlib roadmap item #5 was framed as "cross-file `use`
resolvability from standalone check", but the actual underlying issue
turned out to be **discoverability**: cross-module `use` already works
(both `use Deno::{Json}` and `use prelude::*` resolve from a standalone
single-file check). What trips users is that prelude is NOT auto-opened
(deliberate, per issue #138), and the error when an unimported `Some`
is referenced was a raw OCaml record dump with no hint about the fix.
This change:
1. Replaces face.ml's `Canonical` branch's `show_resolve_error` (raw
record dump) with a real per-error-class formatter. Other faces
were already formatted; only Canonical hadn't been touched here.
2. Adds a `prelude_hint` helper in both face.ml and typecheck.ml that,
when an undefined name matches a known prelude export, appends:
hint: `Some` is defined in `stdlib/prelude.affine` — add
`use prelude::{Some};` (or `use prelude::*;`) at the top of
the file.
Covers both the resolve-time path (face.ml) and the typecheck-time
path (typecheck.ml's UnboundVariable — fires e.g. when a match arm
references an unbound constructor the resolver missed).
3. Hard-codes the prelude export list as the well-known 20 names
(Option, Result, Some, None, Ok, Err + the function helpers). A
missing name here means a worse error message, not incorrect
behaviour. Comment in both files notes the list must mirror
`stdlib/prelude.affine`.
Effect for users:
- BEFORE: `Resolution error: (Resolve.UndefinedVariable { Ast.name = "Some"; span = {...} })`
- AFTER:
```
Resolution error: undefined value: `Some`
hint: `Some` is defined in `stdlib/prelude.affine` — add
`use prelude::{Some};` (or `use prelude::*;`) at the top of
the file.
```
Doesn't auto-import prelude (would revert #138). Doesn't change resolve
behaviour at all — only error rendering.
Test plan:
- [x] codegen-deno suite stays 7/7 green
- [x] Manual reproduction of the idaptik PR #107 case shows the hint
- [x] Non-prelude names (e.g. `nonexistentFn`) still get a clean error
with NO inappropriate prelude hint
- [x] `dune build bin/main.exe` clean
Updates stdlib roadmap row #5 status `◑` partial → `●` usable in a
follow-up PR (so this PR stays focused on the diagnostic).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent b95852f commit c587aa4
2 files changed
Lines changed: 61 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
549 | 549 | | |
550 | 550 | | |
551 | 551 | | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
552 | 575 | | |
553 | 576 | | |
554 | 577 | | |
555 | | - | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
556 | 595 | | |
557 | 596 | | |
558 | 597 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
116 | 136 | | |
117 | 137 | | |
118 | | - | |
| 138 | + | |
119 | 139 | | |
120 | 140 | | |
121 | 141 | | |
| |||
0 commit comments