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

[wgsl-in] Confusing error: "expected unsigned/signed integer literal, found '1'" #1996

Closed
kpreid opened this issue Jun 29, 2022 · 2 comments · Fixed by #2075
Closed

[wgsl-in] Confusing error: "expected unsigned/signed integer literal, found '1'" #1996

kpreid opened this issue Jun 29, 2022 · 2 comments · Fixed by #2075
Labels
area: front-end Input formats for conversion lang: WGSL WebGPU shading language

Comments

@kpreid
Copy link

kpreid commented Jun 29, 2022

I'm not familiar with the WGSL specification and couldn't figure it out quickly, so I'm not sure if this is a validation error or merely a poor error message. Given that it used to be accepted, I'm guessing the latter.

The following passes validation with naga 0.8.5 (current crates.io release) but fails on git (as of commit 27d38aa)

fn switcher(input: u32) {
    switch (input) {
        case 1: {}
        default: {}
    }
}
error: expected unsigned/signed integer literal, found '1'
  ┌─ test.wgsl:3:14
  │
3 │         case 1: {}
  │              ^ expected unsigned/signed integer literal

The error goes away if I change 1 to 1u, making it explicitly unsigned. If this program should pass validation, then the message is quite confusing: it doesn't specify that I need an unsigned integer, and it doesn't make it clear that this is a type mismatch and not a syntax error.

@teoxoy
Copy link
Member

teoxoy commented Jun 29, 2022

This seems to be a side-effect of #1863.

The tokenizer now differentiates between concrete types (those with suffixes) and abstract ones.

The plan is to infer the type of abstract numbers as per spec (improving the errors in the process).

@teoxoy
Copy link
Member

teoxoy commented Nov 17, 2022

Track gfx-rs/wgpu#4400 for automatic type conversions.

jimblandy added a commit to SparkyPotato/naga that referenced this issue Jan 12, 2023
Fixes gfx-rs#1745: Support out-of-order module scope declarations in WGSL
Fixes gfx-rs#1044: Forbid local variable shadowing in WGSL
Fixes gfx-rs#2076: [wgsl-in] no error for duplicated type definition
Fixes gfx-rs#2071: Global item does not support 'const'
Fixes gfx-rs#2105: [wgsl-in] Type aliases for a vecN<T> doesn't work when constructing vec from a single argument
Fixes gfx-rs#1775: Referencing a function without a return type yields an unknown identifier error.
Fixes gfx-rs#2089: Error span reported on the declaration of a variable instead of its use
Fixes gfx-rs#1996: [wgsl-in] Confusing error: "expected unsigned/signed integer literal, found '1'"

Separate parsing from lowering by generating an AST, which desugars as
much as possible down to something like Naga IR. The AST is then used
to resolve identifiers while lowering to Naga IR.

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
Co-authored-by: Jim Blandy <jimb@red-bean.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: front-end Input formats for conversion lang: WGSL WebGPU shading language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants