Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[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.
  • Loading branch information
jimblandy committed Nov 30, 2023
commit 3bcb6da8c658b21ed0f6de08a3404b2037c0ec69
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
Loading