Skip to content

Allow return in a switch expression #4214

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

Closed
andrei-toterman opened this issue Dec 20, 2024 · 2 comments
Closed

Allow return in a switch expression #4214

andrei-toterman opened this issue Dec 20, 2024 · 2 comments
Labels
feature Proposed language feature that solves one or more problems

Comments

@andrei-toterman
Copy link

This compiles just fine

void f(int x) {
  x = switch (x) {
      _ => throw Exception(),
  };
}

but this does not

void f(int x) {
  x = switch (x) {
      _ => return,
  };
}

But I think those should behave the same way, not assigning x any value and not caring about its type, since the function is about to be exited.

@andrei-toterman andrei-toterman added the feature Proposed language feature that solves one or more problems label Dec 20, 2024
@julemand101
Copy link

I feel like this might be duplicate of #2025 or at least another case for that.

@andrei-toterman
Copy link
Author

AH, yes, you are right. Thanks for pointing that out! I'll close this.

@andrei-toterman andrei-toterman closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

2 participants