Skip to content

Matching Exhaustively Over Rust Signals in Dart #638

@ajoklar

Description

@ajoklar

Describe the Bug

(I'm using rinf cli v8.7.2)
When exporting a Rust enum as a signal, matching is a bit off inside Dart switch statements.

To Reproduce

  1. Create a RustSignal enum:
#[derive(Serialize, RustSignal)]
pub enum MyState {
    A(String),
    B(i64),
}
  1. Create a switch statement in Dart:
switch (myState.message) {
    MyStateA(:final value) => handleA(value),
    MyStateB(:final value) => handleB(value),
}

Expected Behavior

I'd expect it to compile, because all enum variants are handled, but the error is:

The type 'MyState' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'MyState()'.
Try adding a wildcard pattern or cases that match 'MyState()'

Proposed Solution

Instead of generating an abstract class MyState, a sealed class MyState would fix the issue. I did the change manually in my code and did not notice any unwanted side effects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions