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

Switch/case documentation gotcha #436

Open
elsassph opened this issue Nov 6, 2019 · 1 comment
Open

Switch/case documentation gotcha #436

elsassph opened this issue Nov 6, 2019 · 1 comment

Comments

@elsassph
Copy link

elsassph commented Nov 6, 2019

"Unintuitively", Haxe cases are absolutely strict, so this can bite:

switch (x) {
   case 1:
   case 2: trace('1 or 2'); // nope, never fall through
 }

And the documentation doesn't explain how to declare a case matching several values - though it is explained deeper in the pattern matching documentation.

Still it's a bit confusing: is it case 1, 2: or case 1 | 2:?

It would be nice for beginners to add something.

@nadako
Copy link
Member

nadako commented Nov 24, 2019

We're talking about this page, right? It contains this sentence:

Case body expressions never "fall through", so the break keyword is not supported in Haxe.

I think we could add a link to or patterns page here. Would that be sufficient?


Still it's a bit confusing: is it case 1, 2: or case 1 | 2:?

It's the | :) AFAIK comma is from the times where there was no proper pattern matching. I don't think we'll remove it any time soon, but I think we pretend that it does not exist. :) (or is it documented anywhere?)

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

No branches or pull requests

2 participants