Skip to content

Improve error messages when keywords are misspelled #1420

Description

@MinekPo1

Currently when a keyword like interface are misspelled, the error is difficult to connect to a typo:

Error: A type name was expected, but this looks a variable or function name (as it doesn't start with an uppercase letter).

This error message can be replaced by contextually checking if the token is close (see edit distance) to a keyword.

in the case of keywords used for top level statement, since IDENT tokens cannot be used in global variable declarations, (as builtin types like int are keywords and custom types are IDENT_TYPE) when encountering an IDENT token in parse_top_level_statement, before calling parse_global_declaration, we can first go through the keywords we could expect and calculating the edit distance to the value and showing a message which explicitly suggests a typo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AcceptedAccepted RequestSemantic AnalysisChanges to semantic behaviour, including compile time folding.
    No fields configured for Feature.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions