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

Should matching construct be a primary expression? #214

Closed
JLHwung opened this issue Jul 19, 2021 · 2 comments
Closed

Should matching construct be a primary expression? #214

JLHwung opened this issue Jul 19, 2021 · 2 comments
Labels
syntax discussion Bikeshedding about syntax, not semantics.

Comments

@JLHwung
Copy link
Contributor

JLHwung commented Jul 19, 2021

The readme mentions that

The pattern matching construct should be usable as an expression:

return match { … }
let foo = match { … }
() => match { … }

Based on the examples, I assume match () {} is a PrimaryExpression, which, if so, will align to other similar structs introduced in proposals like do-expressions and module blocks.

Being a primary expression means that besides the examples mentioned above, the following codes are also valid, I don't see a strong reason to disallow them.

match (res) { when (200) { res } }.code // match can start a member chain without parenthesis
match (res) { when (200) { res } } + 1 // match can be in BinaryExpression without parenthesis

We will then need to modify AssignmentTargetType to disallow match in LHS:

match (res) { when (200) { res } } = 1
match (res) { when (200) { res } } += 1
@ljharb
Copy link
Member

ljharb commented Jul 19, 2021

I agree that both of the first two should be valid, and the last two should not be.

@ljharb ljharb added the syntax discussion Bikeshedding about syntax, not semantics. label Jul 19, 2021
@mpcsh
Copy link
Member

mpcsh commented Dec 6, 2021

I've captured this information and will merge it into the repo for future reference.

@mpcsh mpcsh closed this as completed Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
syntax discussion Bikeshedding about syntax, not semantics.
Projects
None yet
Development

No branches or pull requests

3 participants