-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Add helpful error message when detecting Rust style enums #4942
Comments
How the error message should look like? Let's use expressive diagnostics and have a detailed error similar to the one Rust is giving in this case: enum E {
A: (),
} Error:
Plus the additional Sway specific in-source help message saying, e.g. "Did you mean |
This help message requires a way for Is it worth the trouble to implement one, or should we instead go with something like "Enum kinds have the form 'Foo : ()' or 'Bar : u32'", without referring to the specific thing the user wrote? |
Indeed you are right, the type formatter is available further down in the type checking phase. I don't think that it's worth the trouble. Let's skip the specific in-source help and display just the general hint how enum variants can look like. |
## Description Fixes #4942. Please do review this carefully. I've added a test triggers the new error message, but I might very well have forgotten to add something somewhere. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Igor Rončević <[email protected]>
Users moving from Rust might be tempted to use the Rust enum syntax:
When the correct Sway syntax is:
This is surprising, so we should have an error message that detects this pattern and asks the developer if they meant the latter.
The text was updated successfully, but these errors were encountered: