[naga wgsl-in] Use a better span for errors in constructors.

When reporting errors in construction expressions, use the span of the
constructor itself (that is, the type name) in preference to the span
of the overall expression. This makes errors easier to follow.
This commit is contained in:
Jim Blandy authored and Teodor Tanasoaia committed 2023-12-04 12:20:22 +01:00
1 parent 1823f8bbdf
commit 07b83ab6c0
2 files changed
+4 -5

No files matched your search

+2 -2
View File
@@ -448,7 +448,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
ctx.try_automatic_conversions_slice(
&mut components,
&Tr::Value(component_ty),
span,
ty_span,
)?;
expr = crate::Expression::Compose { ty, components };
}
@@ -497,7 +497,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
// Array constructor, explicit type
(components, Constructor::Type((ty, &crate::TypeInner::Array { base, .. }))) => {
let mut components = components.into_components_vec();
ctx.try_automatic_conversions_slice(&mut components, &Tr::Handle(base), span)?;
ctx.try_automatic_conversions_slice(&mut components, &Tr::Handle(base), ty_span)?;
expr = crate::Expression::Compose { ty, components };
}
+2 -3
View File
@@ -213,9 +213,8 @@ fn constructor_parameter_type_mismatch() {
┌─ wgsl:3:21
│
3 │ _ = mat2x2<f32>(array(0, 1), vec2(2, 3));
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ │ │
│ │ this expression has type array<{AbstractInt}, 2>
│ ^^^^^^^^^^^ ^^^^^^^^^^^ this expression has type array<{AbstractInt}, 2>
│ │
│ a value of type vec2<f32> is required here
"#,