Skip to content

match should be usable as an expression #32

Description

@NightmarePog

Right now `match` is statement-only, so you can't use it on the right side of an assignment or directly in a return. You have to introduce a mutable binding and assign inside each arm:

```
mut result = 0
match shape {
Circle(r) => { result = 3 * r * r }
Rect(w, h) => { result = w * h }
}
return result
```

If `match` were an expression this would just be:

```
return match shape {
Circle(r) => 3 * r * r
Rect(w, h) => w * h
}
```

This pairs naturally with exhaustiveness checking — an exhaustive match expression has a well-defined type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions