Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ErichDonGubler opened this issue Mar 7, 2025 · 0 comments
Labels
area: naga front-end kind: diagnostics Error message should be better lang: WGSL WebGPU Shading Language naga Shader Translator type: enhancement New feature or request

Comments

@ErichDonGubler
Copy link
Member

ErichDonGubler commented Mar 7, 2025

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. 🙂

@ErichDonGubler ErichDonGubler added area: validation Issues related to validation, diagnostics, and error handling naga Shader Translator area: naga front-end lang: WGSL WebGPU Shading Language kind: diagnostics Error message should be better type: enhancement New feature or request and removed area: validation Issues related to validation, diagnostics, and error handling labels Mar 7, 2025
@ErichDonGubler ErichDonGubler marked this as a duplicate of #7226 Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga front-end kind: diagnostics Error message should be better lang: WGSL WebGPU Shading Language naga Shader Translator type: enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

1 participant