Skip to content

Type mismatch diagnostic suggests to append integer literal suffix to non-literal const expressions #7226

@ErichDonGubler

Description

@ErichDonGubler

Repro steps

  1. Run the following in Naga, i.e., cargo run -p naga ../in.wgsl:

    const my_unsigned_int: u32 = 1u;
    
    @compute @workgroup_size(1, 1, 1)
    fn main() {
        let my_signed_int: i32 = 1i;
    
        switch (my_signed_int) {
            case my_unsigned_int: {
                break;
            }
        }
    }

    Observe that the following error message is returned:

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.37s
     Running `target\debug\naga.exe ../in.wgsl`
Could not parse WGSL:
error: invalid switch value
  ┌─ ../in.wgsl:8:14
  │
8 │         case my_unsigned_int: {
  │              ^^^^^^^^^^^^^^^ expected signed integer
  │
  = note: remove the `u` suffix: `my_unsigned_in`


error: process didn't exit successfully: `target\debug\naga.exe ../in.wgsl` (exit code: 1)

Expected vs observed behavior

We definitely shouldn't suggest this unless the expression is a single literal. We might adjust it by suggesting a constructor, i.e., i32(…), instead when there is something more complicated than a single literal present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: naga front-endTranslation to Naga IRarea: validationIssues related to validation, diagnostics, and error handlingkind: diagnosticsError message should be betternagaShader Translatortype: bugSomething isn't working

    Type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions