Skip to content

Add detailed diagnostics for Rust-style enums #7047

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

kfastov
Copy link

@kfastov kfastov commented Mar 30, 2025

Description

Adds detailed error messages when detected Rust-style enums

close #5403

Changes:

  • Modified enum variant parsing in sway-parse/src/item/mod.rs to detect Rust-like tuple (Variant(T)), unit (Variant), and struct (Variant { field: T }) syntax, generating errors.
  • Updated ParseErrorKind::MissingColonInEnumTypeField in sway-error/src/parser_error.rs to store variant_name and optional tuple_contents span for diagnostic purposes.
  • Added diagnostic generation in sway-error/src/error.rs to output error messages and syntax suggestions (e.g., Did you mean 'Variant: (T)'?) for incorrect enum definitions.
  • Updated the enum_rust_like test (main.sw and test.toml) with new test cases for these syntax errors and adjusted expectations for the new diagnostic output.

All error messages match the spec defined in the issue description.

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@kfastov kfastov requested a review from a team as a code owner March 30, 2025 16:22
@fuel-cla-bot
Copy link

fuel-cla-bot bot commented Mar 30, 2025

Thanks for the contribution! Before we can merge this, we need @kfastov to sign the Fuel Labs Contributor License Agreement.

@kfastov kfastov changed the title Feat/rust enum diagnostics Feature: rust enum diagnostics Mar 30, 2025
@kfastov kfastov changed the title Feature: rust enum diagnostics Add rust enum diagnostics Mar 30, 2025
Copy link
Contributor

@IGI-111 IGI-111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs more polish (since the point here is to have as helpful errors as possible) but you're on the right track I think.

@IGI-111 IGI-111 requested a review from ironcev March 31, 2025 08:43
@kfastov
Copy link
Author

kfastov commented Apr 10, 2025

@IGI-111 @ironcev
Hi, sorry for the long delay, I've fixed all the error messages now.
About updating docs: I don't think I change any APIs, and affected error messages are not mentioned in the documentation, so I skipped this part. Please tell me if I need to document anything.
It also doesn't seem like a breaking change to me

@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: parser Everything to do with the parser labels Apr 11, 2025
@ironcev ironcev changed the title Add rust enum diagnostics Add detailed diagnostics for Rust-style enums Apr 11, 2025
Copy link
Member

@ironcev ironcev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, very clean and well documented implementation! Thanks for taking this over @kfastov!

Just one small detail to change.

@ironcev ironcev requested a review from IGI-111 April 13, 2025 09:00
@kfastov
Copy link
Author

kfastov commented May 4, 2025

@IGI-111 Hi, sorry for bothering you, should I do something else for this PR to be reviewed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:signed compiler: parser Everything to do with the parser compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add detailed error message with solution when detecting Rust style enums
3 participants