Skip to content

Is it worth to suggest to explicitly forbid declaration patterns for case of multiple switch_label in single switch_section #7786

Answered by HaloFour
gurustron asked this question in Q&A
Discussion options

You must be logged in to vote

I forget the name of the proposal (can look it up later) but there is one for allowing overlap of the pattern variables between disjunctive patterns that would allow something like this:

switch (obj) {
    case Person(string name):
    case Business(string name):
        // can use name here, it's definitely assigned by one of the two patterns
        break;
}

And while those variables aren't definitely assigned, they could be within the switch block and then they could be used.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ufcpp
Comment options

Answer selected by gurustron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants