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

proposal: spec: add optional simple statement to expression switch statement #23110

Closed
willfaught opened this issue Dec 12, 2017 · 2 comments
Closed

Comments

@willfaught
Copy link
Contributor

It executes before the switch expression is evaluated, if any:

switch g := employee.Attributes.Gender; g {
case person.GenderFemale, person.GenderMale, person.GenderOther:
    return g
}

switch a := employee.Attributes {
case a.IsActive, a.OnVacation, a.OnMaternityLeave:
    return a.Name
}

Same reasoning as having an optional simple statement in the if statement.

I suspect this will be denied, even for Go 2, but I didn't see any other issues about it, and I'm curious what the reasoning was for not having it.

@gopherbot gopherbot added this to the Proposal milestone Dec 12, 2017
@mvdan
Copy link
Member

mvdan commented Dec 12, 2017

Perhaps I'm missing something, but this already exists: https://golang.org/ref/spec#ExprSwitchStmt

@willfaught
Copy link
Contributor Author

Ugh, I could have sworn I saw a compiler error about it, and I was right there in the spec too. Please ignore, I'm dumb.

@golang golang locked and limited conversation to collaborators Dec 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants