Skip to content

Commit cc74173

Browse files
fix(wgsl-in): print debug repr. of unexpected tokens (#6907)
1 parent f62090e commit cc74173

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

naga/src/front/wgsl/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl<'a> Error<'a> {
409409
};
410410
ParseError {
411411
message: format!(
412-
"expected {}, found '{}'",
412+
"expected {}, found {:?}",
413413
expected_str, &source[unexpected_span],
414414
),
415415
labels: vec![(unexpected_span, format!("expected {expected_str}").into())],

naga/tests/wgsl_errors.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn reserved_identifier_prefix() {
5252
fn function_without_identifier() {
5353
check(
5454
"fn () {}",
55-
r###"error: expected identifier, found '('
55+
r###"error: expected identifier, found "("
5656
┌─ wgsl:1:4
5757
5858
1 │ fn () {}
@@ -66,7 +66,7 @@ fn function_without_identifier() {
6666
fn invalid_integer() {
6767
check(
6868
"fn foo([location(1.)] x: i32) {}",
69-
r###"error: expected identifier, found '['
69+
r###"error: expected identifier, found "["
7070
┌─ wgsl:1:8
7171
7272
1 │ fn foo([location(1.)] x: i32) {}
@@ -80,7 +80,7 @@ fn invalid_integer() {
8080
fn invalid_float() {
8181
check(
8282
"const scale: f32 = 1.1.;",
83-
r###"error: expected identifier, found ';'
83+
r###"error: expected identifier, found ";"
8484
┌─ wgsl:1:24
8585
8686
1 │ const scale: f32 = 1.1.;
@@ -1797,7 +1797,7 @@ fn binary_statement() {
17971797
3 + 5;
17981798
}
17991799
",
1800-
r###"error: expected assignment or increment/decrement, found ';'
1800+
r###"error: expected assignment or increment/decrement, found ";"
18011801
┌─ wgsl:3:18
18021802
18031803
3 │ 3 + 5;
@@ -2432,3 +2432,17 @@ fn const_assert_failed() {
24322432
"###,
24332433
);
24342434
}
2435+
2436+
#[test]
2437+
fn reject_utf8_bom() {
2438+
check(
2439+
"\u{FEFF}fn main() {}",
2440+
r#"error: expected global item ('struct', 'const', 'var', 'alias', 'fn', 'diagnostic', 'enable', 'requires', ';') or the end of the file, found "\u{feff}"
2441+
┌─ wgsl:1:1
2442+
2443+
1 │ fn main() {}
2444+
│ expected global item ('struct', 'const', 'var', 'alias', 'fn', 'diagnostic', 'enable', 'requires', ';') or the end of the file
2445+
2446+
"#,
2447+
);
2448+
}

0 commit comments

Comments
 (0)