-
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
Improve error message for illegal enum variants #5397
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few slight changes in the message text, to make it compatible with the diagnostic guidelines.
Since this is a new diagnostic, we also need to add the Diagnostic
to the error, this is missing currently.
We don't have Diagnostic
so far in the parsing phase, so let's leave that part out for now.
test/src/e2e_vm_tests/test_programs/should_fail/enum_rust_like/src/main.sw
Outdated
Show resolved
Hide resolved
test/src/e2e_vm_tests/test_programs/should_fail/enum_rust_like/src/main.sw
Outdated
Show resolved
Hide resolved
test/src/e2e_vm_tests/test_programs/should_fail/enum_rust_like/src/main.sw
Outdated
Show resolved
Hide resolved
test/src/e2e_vm_tests/test_programs/should_fail/enum_rust_like/test.toml
Outdated
Show resolved
Hide resolved
test/src/e2e_vm_tests/test_programs/should_fail/enum_rust_like/test.toml
Outdated
Show resolved
Hide resolved
@jjcnn @IGI-111 This minimal change is already a big improvement compared to what we have now. It clearly indicates the issue and the expected variant formats. So I'm definitely for merging it. However, after giving it additional thought, I'm thinking again about a bit more ambitious solution, which was my original thought on the GitHub issue. Recognizing Rust specific patterns and showing concrete solution for the issue, how the same code should look in Sway. That would mean adding
We do not have to parse the Rust struct-like variant. That would be a bit too much work, and it's also not a kind of a mistake Sway programmers do. In that and all other cases we can go for the common help message at the bottom of the message without the particular suggestion.
But for the other three cases, having a precise solution in the error message has a benefit. Also, adding the first Let me know what you think. |
I think it is a good idea to get additional information to help the most common issues, but unless Rust confusions are really that common it's probably over-engineering. Helpful errors are important and I really like your examples, but improving errors for cases that aren't as niche is likely a better use of our ressources at this time. Maybe you should put this idea in a separate issue and we can bikeshed it and/or pick it up when we'll have a serious go at polishing our errors. In any case, we should get this PR's improvement first. |
Done: #5403 |
Co-authored-by: Igor Rončević <[email protected]>
…/src/main.sw Co-authored-by: Igor Rončević <[email protected]>
…/src/main.sw Co-authored-by: Igor Rončević <[email protected]>
…/src/main.sw Co-authored-by: Igor Rončević <[email protected]>
Review comments addressed. |
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
Breaking*
orNew Feature
labels where relevant.