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

Discard pattern in switch and is #30650

Closed
gafter opened this issue Oct 22, 2018 · 1 comment
Closed

Discard pattern in switch and is #30650

gafter opened this issue Oct 22, 2018 · 1 comment

Comments

@gafter
Copy link
Member

gafter commented Oct 22, 2018

From dotnet/csharplang#1054

Is the discard pattern permitted at the top level of a switch statement? If so, it could change the meaning of existing code. I suggest we require you write case var _ to avoid any ambiguity.

Resolution 2018-10-10: A discard pattern in the presence of a constant will bind to the constant only in a switch statement case, with a warning given under a warning wave. Elsewhere in a pattern it is a discard pattern. A discard pattern in an is-expression in the presence of a type will bind to the type, with a warning under a warning wave.

@gafter gafter added this to the 16.0 milestone Oct 22, 2018
@gafter gafter self-assigned this Oct 22, 2018
gafter added a commit to gafter/roslyn that referenced this issue Oct 30, 2018
- A discard pattern is not accepted at the top level in a switch statement. In that case `_` binds to a constant in scope with a warning WRN_CaseConstantNamedUnderscore that is included in a warning wave.
- A discard pattern is not accepted at the top level in an is-expression. In that case `_` binds to a type in scope with a warning WRN_IsTypeNamedUnderscore that is included in a warning wave.
- Elsewhere a pattern `_` is a discard without warning no matter what definition for `_` might be in scope.

Fixes dotnet#30650
See also dotnet#30846
gafter pushed a commit that referenced this issue Nov 6, 2018
* Discard pattern versus symbol named `_`

- A discard pattern is not accepted at the top level in a switch statement. In that case `_` binds to a constant in scope with a warning WRN_CaseConstantNamedUnderscore that is included in a warning wave.
- A discard pattern is not accepted at the top level in an is-expression. In that case `_` binds to a type in scope with a warning WRN_IsTypeNamedUnderscore that is included in a warning wave.
- Elsewhere a pattern `_` is a discard without warning no matter what definition for `_` might be in scope.

Fixes #30650
See also #30846
@gafter
Copy link
Member Author

gafter commented Nov 6, 2018

Fixed in #30847

@gafter gafter closed this as completed Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant