Skip to content

Conversation

reima
Copy link
Contributor

@reima reima commented Aug 28, 2025

Connections
Fixes #8126.

Description
This change allows a trailing comma in the list of case values inside a switch.

It accomplishes this by checking if a comma is followed by a : (indicating the list of values ends here), or an attribute or { token (indicating that a compound statement follows).

Testing
I've extended naga\tests\in\wgsl\control-flow.wgsl to contain a switch with trailing commas.

Squash or Rebase?

Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

Copy link
Contributor

@andyleiserson andyleiserson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion, but it's not critical and otherwise this looks good. Thanks for the PR!

Comment on lines 2295 to 2296
| Token::Attribute
| Token::Paren('{')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest making a helper Token::is_start_of_compound_statement for matches!(token, Token::Attribute | Token::Paren('{')). It could be used here and on line 2124 where fn statement parses compound statements. This better encapsulates the sensitivity to a rule from elsewhere in the grammar and reduces the risk of bugs if the grammar changes in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea! Adding the helper to Token didn't feel right to me, so I've added a free function instead.

@ErichDonGubler ErichDonGubler added naga Shader Translator area: naga front-end lang: WGSL WebGPU Shading Language labels Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga front-end lang: WGSL WebGPU Shading Language naga Shader Translator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch case not compiling
3 participants