Skip to content

Commit

Permalink
[naga wgsl-in] Use a better span for errors in constructors.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jimblandy authored and teoxoy committed Dec 4, 2023
1 parent 1823f8b commit 07b83ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions naga/src/front/wgsl/lower/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down Expand Up @@ -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 };
}

Expand Down
5 changes: 2 additions & 3 deletions naga/tests/wgsl_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"#,
Expand Down

0 comments on commit 07b83ab

Please sign in to comment.