Skip to content

Implement match expression for pattern matching #164

@LunaStev

Description

@LunaStev

Background:

Wave currently supports if, while, and function calls, but lacks a native pattern matching construct.
Adding a match expression would allow more expressive and readable control flow, especially for handling enums, constant values, and future Option-like types.

Expected Behavior:

A match expression should support matching against values with multiple arms, including a default case.
For example:

fun main() {
    var x: i32 = 2;

    match x {
        1 => println("one"),
        2 => println("two"),
        _ => println("something else"),
    }
}
  • Each arm should end with an expression or block.

  • A wildcard (_) must be supported as a fallback/default case.

  • Future support should allow nested match, enum matching, and more.

User Scenarios:

  1. A developer wants to replace multiple if-else chains with cleaner, declarative syntax.
  2. Future enum-based APIs (e.g., Option, Result) require pattern-based branching.
  3. Improves readability in cases like command parsing, state machines, or integer mapping.

Additional Information:

  • Language version: - (not yet assigned)

  • Target branch: develop

  • Parser and compiler will need updates to support match as an expression

  • Could later expand to support destructuring and pattern guards

Metadata

Metadata

Assignees

Labels

discussionIssues that require a technical or community discussion.enhancementA request for a new feature or improvement.feature requestA request for a new feature or functionality.

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions