Skip to content

Non-exhaustive enums, variants, records, function params #454

Open
@MendyBerger

Description

@MendyBerger

Currently, adding a new case to an enum or variant, would likely be a breaking change, as user code needs to handle a new case.

It would be great to have some sort of non-sealed attribute that would indicate to language bindings that this enum/variant can get new cases, and therefore should require a fall through case when matching on them.
This would be similar to the #[non_exhaustive] attribute in Rust, and IIUC is default in Swift unless opted out with @frozen.

The same can probably also be done for records and function parameters. As long as the new fields/parameters have default values, they should be able to evolve without requiring a breaking change.

This problem came up in wasi:webgpu. In WebGPU, feature detection and feature requests are done with strings, as JS doesn't have enums (feature detection, feature requests). This allows the api to evolve over time without making breaking changes.
If we wanna use real enums in wasi:webgpu , we need a way to let them grow without making breaking changes. Otherwise we'll be stuck on the first version of WebGPU.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions