Skip to content

fix(check): say a def given <...> is a def, and how a do block opens - #1865

Merged
nicolas-abril merged 3 commits into
bendlang:mainfrom
nicolas-abril:fix/def-angle-args
Oct 27, 2026
Merged

nicolas-abril merged 3 commits into
bendlang:mainfrom
nicolas-abril:fix/def-angle-args

Conversation

@nicolas-abril

@nicolas-abril nicolas-abril commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Two easy slips gave errors that didn't point at the fix:

def main() -> IO<Unit>:     # a def written with a datatype's <...>
  do IO(Unit):              # a do block's effect written with (...)

The first reported a declared datatype (unknown: IO), although IO is defined. The second reported only expected '<'.

Neither problem is specific to IO. Any def written as X<...> hits the first, and any do M without its < hits the second. So instead of a special case for IO (as in #1835), both errors now come from what the name is and what was written:

  • book_adt. A name in type position is either a datatype or a def. A def keeps a declared datatype and adds Note: X is a def: write its arguments as (), the mirror of the existing Note: X is a datatype: write its arguments as <>. The name comes through name_show, so an imported def reads as the file spells it (L.Twice, not lib.Twice). A def with no parameters notes Note: X is a def with no arguments: write it as X instead, since the slip is the <...> itself. An unknown name keeps (unknown: X).
  • The do parser. A missing < now reports '<' (a do block is written do M<...>:), with the effect the user wrote, whatever follows the name. The header checks nothing about the name.
  • A missing .bind / .pure. A do block on M desugars to M.bind and M.pure. When one is undefined, the a defined name error now notes a do block on M calls M.bind and M.pure, so the error no longer names only a call the user never wrote.

Tests

  • tests/check/def_type_args.bend (new): Twice<U32> for a user-defined def Twice(A: Type) -> Type.
  • tests/parse/do_effect_parens.bend (new): do IO(Unit):, from fix(check): name the type and effect spellings of IO when one is used for the other #1835.
  • tests/check/def_type_args_none.bend (new): Num<U32> for def Num() -> Type.
  • tests/parse/do_missing_param.bend: do Result: now pins the new message.
  • tests/check/do_missing_bind.bend: do Box<>: with no Box.bind now pins the note.

What I ran

  • Test gate: 1723/1723. Repo gate: 54/54.
  • IO<Unit> as a return type reports a declared datatype with Note: IO is a def: write its arguments as ().
  • A def from a file imported as L, written L.Twice<U32>, gets Note: L.Twice is a def: ... (before this, it showed the internal lib.Twice).

Supersedes #1835 (thanks @adeerkhan, who is co-author on the commit).

🤖 Generated with Claude Code

A def written with a datatype's <...> arguments reported "a declared
datatype (unknown: X)", though X is defined: it now says X is a def,
applied as X(...). An unknown name keeps "unknown". A do block whose
effect lacks its '<' expected only '<': it now shows the block written
with the effect it names, do M<...>:. Neither is about IO, though
`IO<Unit>` as a return type and `do IO(Unit):` are the common slips.

From bendlang#1835, without its IO case.

Co-Authored-By: Adeer Khan <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Thanks, the general version is better than the IO special case. I merged it onto main d30d7dd: test 1729/1729, repo 54/54, ping 81/81 and safe (0 false rejects) all pass. Perf is noise (main misses cells on the same rerun). bend.ts goes from 44,067 to 44,135 ttok.

The checker and parser behave correctly; these comments are only about what the new messages say.

  1. The def hint shows the internal path, not the name the user wrote (book_adt). Through an import alias:

    import lib/tw.bend as L
    def main() -> L.Twice<U32>:
    

    reports a declared datatype (lib/tw.Twice is a def, applied as lib/tw.Twice(...)), which can't be written; the fix is L.Twice(U32). Spelling it with name_show instead of name_key would match the user's file. The "unknown" message spells names the same way already, but this hint is one the user is meant to copy. I'd fix this one before merge.

  2. The do hint shows for any name, even one that can't head a do block. do Twice(U32): with a plain def, or do Nope(U32): with nothing defined, both get (a do block is written do Twice<...>:). Following the hint then fails with expected a defined name, observed Twice.pure. Maybe show the hint only when M.bind / M.pure exist?

  3. A def without arguments gets the wrong advice. With def Num() -> Type: U32, writing Num<U32> reports applied as Num(...), but the mistake is the extra <U32>: Num and Num() both check. The hint could depend on the def's arity.

  4. The opposite mistake (a datatype applied with (), bend.ts:3585) puts its hint in an Err note, Note: X is a datatype: write its arguments as <>. Passing this one as the note too would keep expected plain and make the two directions read the same.

  5. Small: the do hunk copies parse_eat's body inline (skip, take, fail) just to add a hint. An optional hint argument on parse_eat, parse_eat(p, "<", hint), would be shorter under the bend.ts cap.

nicolas-abril and others added 2 commits October 26, 2026 21:16
…does

The def case keeps "a declared datatype" and adds "Note: X is a def:
write its arguments as ()", the mirror of the datatype note. Its name
comes through name_show, so an imported def reads as the file spells
it (L.Twice, not lib.Twice). The do block's hint drops a name_key that
did nothing: m is the name as written.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…call

A def with no parameters given <...> notes "write it as X": the slip is
the arguments, and X(...) would only move it. An undefined X.bind or
X.pure, the calls a do block on X desugars to, notes that the do block
calls them, so a do block on a name with neither no longer fails on a
name the user never wrote. The do header still checks nothing.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@nicolas-abril

Copy link
Copy Markdown
Collaborator Author

Thanks @Lorenzobattistela! Going through the points:

  1. Internal path in the def hint. Fixed in c76f9c5: the name now comes through name_show, so L.Twice<U32> reports L.Twice.
  2. The do hint for any name. I'd rather not check at the do header whether M.bind / M.pure exist. The real problem is the error you get once they're missing, so 28fc5de improves that. An undefined X.bind or X.pure now notes a do block on X calls X.bind and X.pure. tests/check/do_missing_bind.bend pins it.
  3. A def with no arguments. Fixed in 28fc5de: it now notes Num is a def with no arguments: write it as Num (tests/check/def_type_args_none.bend).
  4. Hint as a note. Done in c76f9c5: expected stays plain, and the hint is Note: X is a def: write its arguments as (), matching the datatype direction.
  5. Hint argument on parse_eat. Skipped. Hinted token failures elsewhere in the parser are inline parse_take + parse_fail (e.g. the '->' hint for a def with no return type), so this follows that convention.

Test gate 1723/1723, repo 54/54.

@nicolas-abril
nicolas-abril merged commit 34c7abb into bendlang:main Oct 27, 2026
1 check passed
@nicolas-abril
nicolas-abril deleted the fix/def-angle-args branch October 27, 2026 15:15
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