Skip to content

Commit

Permalink
fix(wgsl-in): print debug repr. of unexpected tokens (#6907)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler authored Jan 13, 2025
1 parent f62090e commit cc74173
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion naga/src/front/wgsl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ impl<'a> Error<'a> {
};
ParseError {
message: format!(
"expected {}, found '{}'",
"expected {}, found {:?}",
expected_str, &source[unexpected_span],
),
labels: vec![(unexpected_span, format!("expected {expected_str}").into())],
Expand Down
22 changes: 18 additions & 4 deletions naga/tests/wgsl_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn reserved_identifier_prefix() {
fn function_without_identifier() {
check(
"fn () {}",
r###"error: expected identifier, found '('
r###"error: expected identifier, found "("
┌─ wgsl:1:4
1 │ fn () {}
Expand All @@ -66,7 +66,7 @@ fn function_without_identifier() {
fn invalid_integer() {
check(
"fn foo([location(1.)] x: i32) {}",
r###"error: expected identifier, found '['
r###"error: expected identifier, found "["
┌─ wgsl:1:8
1 │ fn foo([location(1.)] x: i32) {}
Expand All @@ -80,7 +80,7 @@ fn invalid_integer() {
fn invalid_float() {
check(
"const scale: f32 = 1.1.;",
r###"error: expected identifier, found ';'
r###"error: expected identifier, found ";"
┌─ wgsl:1:24
1 │ const scale: f32 = 1.1.;
Expand Down Expand Up @@ -1797,7 +1797,7 @@ fn binary_statement() {
3 + 5;
}
",
r###"error: expected assignment or increment/decrement, found ';'
r###"error: expected assignment or increment/decrement, found ";"
┌─ wgsl:3:18
3 │ 3 + 5;
Expand Down Expand Up @@ -2432,3 +2432,17 @@ fn const_assert_failed() {
"###,
);
}

#[test]
fn reject_utf8_bom() {
check(
"\u{FEFF}fn main() {}",
r#"error: expected global item ('struct', 'const', 'var', 'alias', 'fn', 'diagnostic', 'enable', 'requires', ';') or the end of the file, found "\u{feff}"
┌─ wgsl:1:1
1 │ fn main() {}
│ expected global item ('struct', 'const', 'var', 'alias', 'fn', 'diagnostic', 'enable', 'requires', ';') or the end of the file
"#,
);
}

0 comments on commit cc74173

Please sign in to comment.