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

Referencing a function without a return type yields an unknown identifier error. #1775

Closed
OptimisticPeach opened this issue Mar 15, 2022 · 0 comments · Fixed by #2075
Closed
Labels
area: front-end Input formats for conversion lang: WGSL WebGPU shading language type: enhancement

Comments

@OptimisticPeach
Copy link

I had code which resembled the following:

fn foo() {
    return vec2<f32>(0.0, 0.0);
}

fn bar() {
    let qux = foo();
}

Note that I forgot a return type on foo. (This was much more difficult to spot at a glance in my actual code).

Validating the code with Naga fails with:

❯ cargo run example.wgsl
    Finished dev [unoptimized + debuginfo] target(s) in 0.23s
     Running `target\debug\naga.exe example.wgsl`
error: no definition in scope for identifier: 'foo'
  ┌─ example.wgsl:6:15
  │
6 │     let qux = foo();
  │               ^^^ unknown identifier

Could not parse WGSL
error: process didn't exit successfully: `target\debug\naga.exe example.wgsl` (exit code: 1)

Whereas I'd expect it to either:

  • Error on foo containing a return statement while it returns nothing, or
  • Tell me that foo returns nothing and assigning to a variable is foolish.
@cwfitzgerald cwfitzgerald added lang: WGSL WebGPU shading language area: front-end Input formats for conversion type: enhancement labels Mar 15, 2022
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 type: enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants