Skip to content

fix(check): name the type and effect spellings of IO when one is used for the other - #1835

Closed
adeerkhan wants to merge 1 commit into
bendlang:mainfrom
adeerkhan:fix/io-effect-spelling
Closed

adeerkhan wants to merge 1 commit into
bendlang:mainfrom
adeerkhan:fix/io-effect-spelling

Conversation

@adeerkhan

Copy link
Copy Markdown
Contributor

Two spellings of IO are easy to swap, and each one reported an error that
never named the other:

import Base

def main() -> IO<Unit>:
  do IO<Unit>:
    IO.print("hello")
Error:
- message  : a declared datatype (unknown: IO)
Location: main
3>| def main() -> IO<Unit>:
  |               ^^^^^^^

The reverse, do IO(Unit):, reported only expected '<' / observed '('.

IO is a base def, not an ADT, so a type written IO<...> fell through to the
"unknown datatype" message; and the do parser expected < without saying
what it was for. Both now name the pair and the position:

  • a return type: a type: IO<...>is the do block's effect syntax; a return type is writtenIO(...)``
  • a do block: an effect's arguments in <...>(a do block isdo IO<...>:, and the type is written IO(...))

The two tests pin both messages and exit 1:

  • tests/check/io_effect_in_return_type.bend
  • tests/parse/do_effect_type_spelling.bend

What I ran: the source compiler (bun bend2/main.ts) on both tests (output
matches the pinned #| lines), gates/repo.ts --gate (PASS 54/54), and a valid
IO(Unit) / do IO<Unit> program (prints hi). gates/test.ts needs the
cluster and BEND_HOC is not set here, so I did not run the full test gate; CI
will.

@nicolas-abril

Copy link
Copy Markdown
Collaborator

Thanks for this! Closing in favour of #1865. The two errors you found aren't really about IO: any def written as X<...> gives the misleading unknown datatype error, and any do M without its < gives the bare expected '<'. So #1865 drops the IO special case and fixes both errors in general. A def given <...> now says X is a def, applied as X(...), and a do block missing its < shows do M<...>: with the effect you wrote. Your do IO(Unit): test is kept, and you're co-author on the commit.

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