Skip to content

Diagnostics: the two spellings of an effect (IO<Unit> vs IO(Unit)) both point the wrong way #1848

Closed

Description

@adeerkhan

Bend 2.0.38. An effect application has two spellings that a newcomer mixes up constantly: the type is written with parentheses (IO(Unit)) and the do-block with angle brackets (do IO<Unit>:). Each mistake produces a diagnostic that does not name the pair or the position, so the fix is not discoverable from the message.

Repro 1 — the return type written with angle brackets:

import Base
def main() -> IO<Unit>:
  do IO<Unit>:
    IO.print("hi")
    return Unit{}
Error:
- message  : a declared datatype (unknown: IO)
Location: main
2>| def main() -> IO<Unit>:
  |               ^^^^^^^

The compiler reports IO as if the program were declaring a datatype named IO, which it is not — it is applying one. Nothing suggests parentheses.

Repro 2 — the do-block written with parentheses:

import Base
def main() -> IO(Unit):
  do IO(Unit):
    IO.print("hi")
    return Unit{}
Error:
- expected : '<'
- observed : '('
Location:
3>|   do IO(Unit):
  |        ^

Syntactically true, but it says neither what to write nor that the angle form belongs to the do-block while the paren form belongs to the type.

Suggested messages, in the shape of the existing diagnostics:

  • Repro 1: the type of an effect is written with parentheses: IO(Unit), not IO<Unit> (the angle form is the do-block's)
  • Repro 2: a do-block takes the angle form: do IO<Unit>:

Both repros are one token away from a working program; the two spellings are the same distinction, so one message could even name the other. Related: #1632 (the diagnostic proposals thread). Happy to send PRs for either message if the wording is agreed — the sites are the type parser and the do-parser.

Activity

  1. adeerkhan commented on Oct 25, 2026

    @adeerkhan
    ContributorAuthor

    This is fixed by #1835 (fix/io-effect-spelling). I ran that branch's compiler on this issue's two repro files: both messages land exactly as the PR's pinned tests say — the return-type case names the pair (a type: IO<...>is the do block's effect syntax; a return type is writtenIO(...)) and the do-block case reports `expected : an effect's arguments in `<...> at the paren — and the correct IO(Unit) / do IO<Unit>: program still compiles. The special case is narrow (only IO; other unknown names keep the old message), so it does not over-reach.

  2. YidaWeng commented on Oct 28, 2026

    @YidaWeng
    Contributor

    This looks fixed on main by #1865 (which superseded #1835).

    I re-ran both repros from the issue body with current main (52637f74):

    Repro 1 (def main() -> IO<Unit>:):

    Error:
    - message  : a declared datatype
    Location: main
    2>| def main() -> IO<Unit>:
      |               ^^^^^^^
    Note: IO is a def: write its arguments as ()
    

    Repro 2 (do IO(Unit):):

    Error:
    - expected : '<' (a do block is written do IO<...>:)
    - observed : '('
    

    Both name the type vs do-block spelling pair now. Happy to see this closed if that matches what you wanted.

  3. YidaWeng commented on Oct 28, 2026

    @YidaWeng
    Contributor

    Closing as fixed by #1865 (verified on main).

  4. YidaWeng commented on Oct 28, 2026

    @YidaWeng
    Contributor

    (Follow-up: I don't have permission to close issues here. Maintainers: please close if the #1865 messages above are enough.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions