mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-04-17 06:26:35 +00:00
[naga wgsl-in] Don't panic printing struct types for conversions.
When a type conversion expression is ill-formed and the operand is a struct type, don't panic trying to format the operand's type for the error message.
This commit is contained in:
parent
b837db37ad
commit
2f7698d390
@ -550,8 +550,14 @@ impl<'source> Lowerer<'source, '_> {
|
||||
// ERRORS
|
||||
|
||||
// Bad conversion (type cast)
|
||||
(Components::One { span, ty_inner, .. }, constructor) => {
|
||||
let from_type = ctx.type_inner_to_string(ty_inner);
|
||||
(
|
||||
Components::One {
|
||||
span, component, ..
|
||||
},
|
||||
constructor,
|
||||
) => {
|
||||
let component_ty = &ctx.typifier()[component];
|
||||
let from_type = ctx.type_resolution_to_string(component_ty);
|
||||
return Err(Box::new(Error::BadTypeCast {
|
||||
span,
|
||||
from_type,
|
||||
|
@ -3390,3 +3390,24 @@ fn struct_names_in_argument_errors() {
|
||||
assert!(variant("1i").is_err());
|
||||
assert!(variant("A()").is_err());
|
||||
}
|
||||
|
||||
/// Naga should not crash just because the type of a
|
||||
/// bad conversion operand is a struct.
|
||||
#[test]
|
||||
fn struct_names_in_conversion_errors() {
|
||||
#[track_caller]
|
||||
fn variant(argument: &str) -> Result<naga::Module, naga::front::wgsl::ParseError> {
|
||||
let input = format!(
|
||||
r#"
|
||||
struct A {{ x: i32, }};
|
||||
fn f() {{ _ = i32({argument}); }}
|
||||
"#
|
||||
);
|
||||
naga::front::wgsl::parse_str(&input)
|
||||
}
|
||||
|
||||
assert!(variant("1.0").is_ok());
|
||||
assert!(variant("1").is_ok());
|
||||
assert!(variant("1i").is_ok());
|
||||
assert!(variant("A()").is_err());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user