Skip to content

Type conversions are not applied to switch selectors #7369

@andyleiserson

Description

@andyleiserson

Description
Type conversions are not applied to switch selectors. Example (from https://math.hws.edu/graphicsbook/demos/c9/diffusion-demo.html, via https://bugzilla.mozilla.org/show_bug.cgi?id=1863457):

Shader '' parsing error: invalid switch value
   ┌─ wgsl:40:18
   │
40 │             case 0 {
   │                  ^ expected unsigned integer
   │
   = note: suffix the integer with a `u`: `0u`

(The error message suggests but does not explicitly show that the selector has type u32. I verified this to be the case.)

https://www.w3.org/TR/WGSL/#switch-statement says:

Type rule precondition: For a single switch statement, the selector expression and all case selector expressions must be of the same concrete integer scalar type.

and

The expressions in the case_selectors must be const-expressions.

This seems a bit underspecified, but we can probably do something reasonable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions