mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[naga wgsl-in] Don't panic printing struct types for initializers.
When an initializer has the wrong type and it's a struct, don't panic trying to format its type for the error message.
This commit is contained in:
@@ -1308,8 +1308,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
|
||||
if !explicit_inner.equivalent(init_inner, &ectx.module.types) {
|
||||
return Err(Box::new(Error::InitializationTypeMismatch {
|
||||
name: name.span,
|
||||
expected: ectx.type_inner_to_string(explicit_inner),
|
||||
got: ectx.type_inner_to_string(init_inner),
|
||||
expected: ectx.type_to_string(explicit_ty),
|
||||
got: ectx.type_to_string(init_ty),
|
||||
}));
|
||||
}
|
||||
ty = explicit_ty;
|
||||
|
||||
@@ -3411,3 +3411,24 @@ fn struct_names_in_conversion_errors() {
|
||||
assert!(variant("1i").is_ok());
|
||||
assert!(variant("A()").is_err());
|
||||
}
|
||||
|
||||
/// Naga should not crash just because the type of a
|
||||
/// bad initializer is a struct.
|
||||
#[test]
|
||||
fn struct_names_in_init_errors() {
|
||||
#[track_caller]
|
||||
fn variant(init: &str) -> Result<naga::Module, naga::front::wgsl::ParseError> {
|
||||
let input = format!(
|
||||
r#"
|
||||
struct A {{ x: i32, }};
|
||||
fn f() {{ var y: i32 = {init}; }}
|
||||
"#
|
||||
);
|
||||
naga::front::wgsl::parse_str(&input)
|
||||
}
|
||||
|
||||
assert!(variant("1").is_ok());
|
||||
assert!(variant("1i").is_ok());
|
||||
assert!(variant("1.0").is_err());
|
||||
assert!(variant("A()").is_err());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user