Skip to content

[naga] automatic conversion in return statements #7493

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

Closed
k2d222 opened this issue Apr 8, 2025 · 2 comments
Closed

[naga] automatic conversion in return statements #7493

k2d222 opened this issue Apr 8, 2025 · 2 comments

Comments

@k2d222
Copy link

k2d222 commented Apr 8, 2025

related #4400

Description
on 24.0.0 naga does not seem to support automatic type conversion in return statements. Is it a bug?

this fails validation

fn foo(x: u32) -> u32 {
    return 0;    // this is ERR, but return 0u; is OK
}
error: Function [0] 'foo' is invalid
  ┌─ wgsl:1:1
  │  
1 │ ╭ fn foo(x: u32) -> u32 {
2 │ │     return 0;
  │ │            ^ naga::Expression [1]
  │ ╰─────────────^ naga::Function [0]
  │  
  = The `return` value Some([1]) does not match the function return value

Repro steps

link to WESL playground. hit compile.

Expected vs observed behavior

The WGSL spec is not completely clear about when automatic conversion is allowed to happen (it is clarified on a case-by-case basis, e.g. for call statements in the overload resolution section, but the return statement spec just says The type of the return value must match the return type of the function.)

I suspect that the spec intent for return expressions is the same as for declarations with an abstract initializer and explicit type, i.e. the expression is automatically converted to the return type if a conversion exists. this is also what tint/dawn does.

@ErichDonGubler
Copy link
Member

Tagging in @jimblandy and @jamienicol.

@jamienicol
Copy link
Contributor

This should have been fixed by #7035. @k2d222 can you still reproduce on trunk?

@github-project-automation github-project-automation bot moved this from Todo to Done in WebGPU for Firefox Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants