Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue Specific Errors for Common Cases #309

Open
InsertCreativityHere opened this issue Oct 19, 2022 · 4 comments
Open

Issue Specific Errors for Common Cases #309

InsertCreativityHere opened this issue Oct 19, 2022 · 4 comments
Assignees
Milestone

Comments

@InsertCreativityHere
Copy link
Member

With the new parser, we emit a general syntax that describes what the parser found, and what valid things should of been there instead. This is fine for general cases, but there are many common syntax errors that we should add more specific error messages for. For instance:

class MyClass {} // Must be inside a module.
struct Foo: Bar {} // Structs don't support inheritance
struct Foo {}
[[attribute]] // Probably should be a local attribute
struct Bar {}

Striking the right balance between addressing common cases without over-doing it will be non-trivial.
But if anyone runs into a common syntax error that they think warrants a specific error message, feel free to post it here!

@ReeceHumphreys
Copy link
Member

Another good error to emit would be if you are using a keyword somewhere by mistake for example:

...
interface I {
    custom();
}

This gives the following error message:

error: expected one of "[", "}", doc_comment, idempotent_keyword, identifier, but found 'CustomKeyword'
 --> foo.slice:4:5
  |
4 |     custom();
  |     ------
  |

Failed: Compilation failed with 1 error(s)

where it would generally be more helpful to have an error message along the lines of you used the keyword custom instead of a valid identifier. Perhaps you want to escape it with \custom ...

@ReeceHumphreys
Copy link
Member

Found another example with the strings_invalid_as_tag_value test. The error emitted for the below slice is expected one of \"-\", integer_literal, but found 'StringLiteral(\"test string\")'. Not very clear.

testOp(a: tag(\"test string\") int32?);

@ReeceHumphreys
Copy link
Member

Once #510 is merged we now have introduced an error for when doc comments are used on parameters, modules, and return memebers. This error would also be a good candidate for ErrorRecovery with a specific message.

@InsertCreativityHere
Copy link
Member Author

For attributes we should add notes about what an attribute can be applied to when it's put on the wrong thing.

@InsertCreativityHere InsertCreativityHere modified the milestones: 0.1, 0.2 Aug 28, 2023
@InsertCreativityHere InsertCreativityHere modified the milestones: 0.2, 0.1.1 Sep 19, 2023
@InsertCreativityHere InsertCreativityHere modified the milestones: 0.1.1, 0.2.1 Nov 28, 2023
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

No branches or pull requests

2 participants