sway icon indicating copy to clipboard operation
sway copied to clipboard

Add detailed diagnostics for Rust-style enums

Open kfastov opened this issue 9 months ago • 3 comments

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

  • [x] I have linked to any relevant issues.
  • [x] 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).
  • [x] 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.
  • [x] I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • [x] I have requested a review from the relevant team or maintainers.

kfastov avatar Mar 30 '25 16:03 kfastov

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

fuel-cla-bot[bot] avatar Mar 30 '25 16:03 fuel-cla-bot[bot]

@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

kfastov avatar Apr 10 '25 13:04 kfastov

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

kfastov avatar May 04 '25 11:05 kfastov

@ironcev @IGI-111

kfastov avatar Jul 03 '25 11:07 kfastov

@IGI-111 From my side this PR is approved quite some time ago. Can we get a second review and approval?

ironcev avatar Jul 03 '25 12:07 ironcev