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 expression as a statement expression #30649

Closed
gafter opened this issue Oct 22, 2018 · 3 comments
Closed

Switch expression as a statement expression #30649

gafter opened this issue Oct 22, 2018 · 3 comments

Comments

@gafter
Copy link
Member

gafter commented Oct 22, 2018

From dotnet/csharplang#1054

It has been requested that we permit a switch expression to be used as a statement expression. In order to make this work, we'd

Permit its type to be void.
Permit a switch expression to be used as a statement expression if all of the switch arm expressions are statement expressions.
Adjust type inference so that void is more specific than any other type, so it can be inferred as the result type.
Resolution 2018-10-10: Yes! This requires a more precise spec, and it needs to handle a?.M() where M() returns an unconstrained T.

This might not be implemented for C# 8, but it would be good if it were.

@gafter gafter added this to the 16.0 milestone Oct 22, 2018
@gafter gafter self-assigned this Oct 22, 2018
@alrz
Copy link
Member

alrz commented Jan 12, 2019

Permit a switch expression to be used as a statement expression if all of the switch arm expressions are statement expressions.

Does this recursively applies to itself - meaning we can nest switch expressions in such switch expressions?

e switch { _ => a switch { _ => M() } };

If this is valid, I'll adjust #31812 accordingly.

@gafter
Copy link
Member Author

gafter commented Jan 12, 2019

@alrz Probably yes, but I would not write any IDE code depending on this getting into C# 8 until it is in the language. It may be some time, or it may not make it into C# 8.

@gafter gafter modified the milestones: 16.0, 16.1 Feb 26, 2019
@jcouv jcouv modified the milestones: 16.1, 16.2 Apr 23, 2019
@gafter gafter modified the milestones: 16.2, 16.3 Jun 3, 2019
@gafter gafter modified the milestones: 16.3, Compiler.Next Jul 4, 2019
@gafter gafter modified the milestones: Compiler.Next, Compiler.Net5 Dec 11, 2019
@gafter gafter assigned 333fred and unassigned gafter Dec 18, 2019
@gafter
Copy link
Member Author

gafter commented Dec 31, 2019

Closing pending LDM decisions about what the feature should look like.

@gafter gafter closed this as completed Dec 31, 2019
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

4 participants