-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
Default cases on switch statements not cascading to below cases #2405
Comments
Hello! I would love to try to solve this problem! |
@karol-janik Thank you very much! Let me give you some pointers on what it needs to be done. The AST corresponding to a switch statement lives here: boa/boa_ast/src/statement/switch.rs Lines 89 to 93 in c4eabd2
Right now, the structure assumes the Next, I'm seeing no problems on the parser side: boa/boa_parser/src/parser/statement/switch/mod.rs Lines 75 to 79 in c4eabd2
Apparently the parser already tries to parse all Finally, the VM byte compiler: boa/boa_engine/src/bytecompiler/statement/mod.rs Lines 152 to 198 in c4eabd2
This needs to be rewritten in order to make the default case cascade to lower cases. I think this is the most difficult part of this problem, since you'll need to preserve the branch order of the switch case while testing for values after the default case. Let me know if you have some questions about the codebase! 😁 |
#2907 Seems to have fixed this, so closing this :) |
Describe the bug
This is mainly a bug divided in possibly two separate, unintended behaviours:
default
is assumed to always be the last case of a switch (which is not true), and automatically breaks out of the case statement. The correct behaviour should be to cascade to subsequent cases.default
case are not tested for.To Reproduce
Expected behaviour
When foo is 1, it should only print
1
. When foo is neither 1 nor 2, it should printdefault
and then1
.Current behaviour
When foo is not 2, it always prints
default
, even if foo is 1.The text was updated successfully, but these errors were encountered: