Skip to content
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

Require switch blocks when declaring variables #3188

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

atjn
Copy link
Contributor

@atjn atjn commented Feb 10, 2024

When declaring variables inside switch cases, the variables are also available in the other switch cases, with some special rules. This is basically never the intention, and can lead to weird bugs. I suggest requiring switch blocks when variables are declared, which limits the scope of the variable to the individual case.

This was referenced Feb 10, 2024
@bobrippling
Copy link
Collaborator

Sounds good, thanks!

@bobrippling bobrippling merged commit ad7aa52 into espruino:master Feb 15, 2024
1 check passed
@atjn atjn deleted the no-case-declarations branch February 15, 2024 09:37
@gfwilliams
Copy link
Member

I just want to check - have you tested all of these apps since you made the changes to them?

Because while I think this is a good thing, there may still be a possibility that wrapping the blocks has actually broken something if the code did actually use the defined variable later?

@atjn
Copy link
Contributor Author

atjn commented Feb 19, 2024

I checked that the variables in the switch cases were only used in that case. I also tested a few apps on my watch just to make sure my approach was valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants