Skip to content

Unknown declaration keywords show generic error instead of listing valid options #9

Closed

Description

@ehartford

Current behavior

If a user tries a declaration form that does not exist:

pub error SubstrateError =
    | OutOfMemory
    | DeviceLost

The compiler may say something like:

error: expected declaration (fn, type, let, use, extern)

This is better than nothing, but it only appears in some contexts and the parenthetical is easy to miss.

Expected behavior

error: unknown declaration keyword 'error'
 --> lib/crux/error.w:1:5
1 | pub error SubstrateError =
  |     ^^^^^
  = help: valid declarations are: fn, type, let, var, use, extern
  = help: to define an error type, use an enum:
  |   pub type SubstrateError = OutOfMemory | DeviceLost

The key improvements:

  1. Name the specific unknown keyword rather than just listing valid ones
  2. Suggest the closest valid alternative when possible
  3. Always show this hint, not just in certain parser states

Broader request

Every parser error that says "expected X" should also say "got Y" with the actual token.

Activity

  1. added
    error-messages
    on Mar 20, 2026
  2. ehartford commented on Mar 20, 2026

    @ehartford
    ContributorAuthor

    The report no longer matches current language behavior: error is now accepted as a top-level declaration keyword, so the parser no longer emits the generic declaration error for that input. Closing this stale issue.

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

    error-messages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions