-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forbid configurables in pattern matching and shadowing (#6289)
## Description This PR: - emits errors when configurables clash with global constants of the same name - forbids shadowing configurables with local constants or variables - forbids matching against configurables in pattern matching Before #6058, it was just the flag `is_configurable` in `TyConstantDecl` that marked constants as configurables. The first two points were implemented for `TyConstantDecl` and, thus, worked both for constants and for configurables. When introducing `TyConfigurableDecl` we forgot to extend those checks to cover the new type declaration. The third point fixes a bug that allowed matching against configurables, although they are not compile-time constants. Originally, matching was done against the configured value, which was treated as a constant, even if changed during the deployment. After introducing `TyConfigurableDecl`, because of a bug, configurables were treated as pattern variable declarations. This PR brings back the original shadowing behavior and forbids matching against configurables in pattern matching. Forbidding configurables in pattern matching can cause confusion, knowing that regular constants can be matched against. A special consideration was given to explain to developers why this is the case. ## Breaking Changes There were two releases in between. Theoretically but unlikely, it could be that some code appeared that e.g., shadows configurables. In such a case, the change in this PR will be breaking and cause compiler errors. ## Demo ![Constant of the same name as configurable already exists](https://github.com/user-attachments/assets/caa84d32-f661-414c-b2e8-869ae2c2d297) ![Configurables cannot be shadowed - Variable](https://github.com/user-attachments/assets/e95675fa-6754-4e33-bb15-ff923dcb5eba) ![Configurables cannot be matched against](https://github.com/user-attachments/assets/aebd6462-d254-484b-abaf-45a3ce7ef263) ## 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). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [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.
- Loading branch information
Showing
42 changed files
with
1,399 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.