Skip to content

Support for enum (enumerations) in Wave #175

@LunaStev

Description

@LunaStev

Background:

Wave currently lacks support for enumerated types, which are commonly used to define a set of named values. Adding enum support will make it easier for developers to represent and handle fixed sets of related constants, such as states, types, or modes, in a type-safe and readable way.

Expected Behavior:

The Wave language should allow users to define enums using a simple and clear syntax. Each enum variant should be associated with an integer value starting from 0 by default, but explicit values should also be supported. Enum types should be strongly typed and usable in variables, conditionals, pattern matching, and function parameters/returns.

Example:

enum Color {
    Red,
    Green,
    Blue = 10,
    Yellow
}

fun print_color(c: Color) {
    if (c == Color::Red) {
        println("The color is red.");
    }
}

User Scenarios:

  1. A developer wants to define a finite set of game states (Start, Playing, Paused, GameOver) and use them in game logic.

  2. An OS developer wants to define different file permission types or error codes using enums.

  3. A library author wants to provide clear and readable configuration options via enums for API users.

Additional Information:

  • Enum support should integrate well with Wave’s type system and LLVM IR generation.

  • Pattern matching and switch-style branching based on enum variants may be considered for future extensions.

  • Enum-to-int and int-to-enum conversions should be explicitly handled or disallowed to preserve type safety.

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