Skip to content

Add helpful labels for naga::front::wgsl::Error::SwitchCaseTypeMismatch #7293

@ErichDonGubler

Description

@ErichDonGubler

Is your feature request related to a problem? Please describe.

As of #7250, diagnostics for mismatched case expressions in switch conditionals are a bit sparse on details; if you run this shader:

fn x(y: i32) {
    switch y {
        case 1u: {}
    }
}

…you get this diagnostic:

error: invalid `switch` case selector value
  ┌─ ../in.wgsl:3:14
  │
3 │         case 1u: {}
  │              ^^ `switch` case selector must have the same type as the `switch` selector expression

Describe the solution you'd like

In @jamienicol's words:

[I]t's not as easy as you might think, to do it well at least. You might want to show the span of the incorrect case, and show correct type, and additionally the span indicating where the correct type came from. But if the nth case statement has the incorrect type, the correct type might be implied by the n-1th case statement. It wouldn't be as simple as showing the span of the selector, as that might be abstract.

Also, if possible, let's suggest nice hints for fixing things, too.

Describe alternatives you've considered

We could do nothing, but that's laaame, boo. 🙂

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions