Skip to content

fix(cli): an error in a def with a ~ parameter names its own file, not base.bend - #2286

Merged
nicolas-abril merged 2 commits into
bendlang:mainfrom
rbmr:fix/cli-location-template
Nov 24, 2026
Merged

nicolas-abril merged 2 commits into
bendlang:mainfrom
rbmr:fix/cli-location-template

Conversation

@rbmr

@rbmr rbmr commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Since #2208, a CLI error ends with --> file:line:col. For an error in a def with a ~ parameter, that line names bend2/base.bend instead of the file the error is in:

import Base

def f(~x: U32) -> U32:
  True{}
$ bend f.bend --check-only
SOME PROOFS FAIL
Error:
- expected : U32
- observed : Bool
Location: f
3 | def f(~x: U32) -> U32:
4>|   True{}
  |   ^^^^^^
5 |
--> /…/bend2/base.bend:4:3

The excerpt and the caret are right. Without the ~, the last line is --> f.bend:4:3. The line and column are the user file's, so the base.bend location is often a blank line or a column past the end of its line. In a file that doesn't import Base, the --> line is missing entirely.

Why

book_location decides a span is Base's when some tld marked b has a type in the span's file. def_check checks a def with ~ parameters in a book of its own: each parameter becomes a tld f~x marked b: true, typed in the def's own file. That book's tlds inherit the others through the prototype, so Object.values sees only those parameter tlds, and they match.

What changes

book_location walks the inherited tlds too (for … in) and skips names with a ~. The other locations are unchanged: an error in an imported file, in the entry, at a missing import, at a template call site like List.map(~U32, ~U32, ~(x => True{}), xs), and in Base itself. For the last one, I appended a broken plain def and a broken template def to a copy of base.bend, and both still print base.bend:<line>:<col>.

tests/io/cli_source_location gains the case above: it returns 3 on main and 0 with this change, on the interpreter and on Bun.

Verified

Linux x86_64, Bun 1.4.0:

  • I ran --check-only on all 1,882 .bend files under tests/ with and without this change. 1,880 print the same output. The other two are existing tests that hit this bug, tests/comptime/err_generic.bend (--> bend2/base.bend:8:3) and tests/page/comp_param_match.bend (--> bend2/base.bend:13:10). With the change, each names its own file at the same line and column. Their #| lines don't include the --> line, so their expected output is unchanged.
  • main.ts grows by 226 characters. I could not run ttok here. By characters, main.ts is about 13k tokens against its 16k cap.

rbmr and others added 2 commits November 24, 2026 00:06
book_location looked for any tld marked b typed in the span's file, which a
def's ~ parameters also match. Base's Bool is enough: only Base's parse
holds it, and a file without Base has no Bool marked b.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nicolas-abril
nicolas-abril merged commit 65f6a13 into bendlang:main Nov 24, 2026
1 check passed
nicolas-abril added a commit to nicolas-abril/bend that referenced this pull request Nov 24, 2026
, bendlang#2224-bendlang#2226, bendlang#2231, bendlang#2285, bendlang#2286, bendlang#2288 and others)

One conflict, in emit_unfold: bendlang#2288 annotates an unfolded call's lets with
the argument types instantiated by the earlier arguments; bendlang#2162's deep unfold
keeps its arguments unannotated there and annotates them the same way after
folding (its type walk renamed D, beside bendlang#2288's T). Both kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants