Skip to content

Commit

Permalink
Give front::wgsl::Error::InitializationTypeMismatch named fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblandy authored and teoxoy committed Oct 23, 2023
1 parent 946745d commit 528bca7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
14 changes: 9 additions & 5 deletions src/front/wgsl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ pub enum Error<'a> {
InconsistentBinding(Span),
TypeNotConstructible(Span),
TypeNotInferrable(Span),
InitializationTypeMismatch(Span, String, String),
InitializationTypeMismatch {
name: Span,
expected: String,
got: String,
},
MissingType(Span),
MissingAttribute(&'static str, Span),
InvalidAtomicPointer(Span),
Expand Down Expand Up @@ -475,15 +479,15 @@ impl<'a> Error<'a> {
labels: vec![(span, "type can't be inferred".into())],
notes: vec![],
},
Error::InitializationTypeMismatch(name_span, ref expected_ty, ref got_ty) => {
Error::InitializationTypeMismatch { name, ref expected, ref got } => {
ParseError {
message: format!(
"the type of `{}` is expected to be `{}`, but got `{}`",
&source[name_span], expected_ty, got_ty,
&source[name], expected, got,
),
labels: vec![(
name_span,
format!("definition of `{}`", &source[name_span]).into(),
name,
format!("definition of `{}`", &source[name]).into(),
)],
notes: vec![],
}
Expand Down
34 changes: 17 additions & 17 deletions src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,22 +911,22 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
if let Some(explicit) = explicit_ty {
if explicit != inferred_type {
let ty = &ctx.module.types[explicit];
let explicit = ty
let expected = ty
.name
.clone()
.unwrap_or_else(|| ty.inner.to_wgsl(ctx.module.to_ctx()));

let ty = &ctx.module.types[inferred_type];
let inferred = ty
let got = ty
.name
.clone()
.unwrap_or_else(|| ty.inner.to_wgsl(ctx.module.to_ctx()));

return Err(Error::InitializationTypeMismatch(
c.name.span,
explicit,
inferred,
));
return Err(Error::InitializationTypeMismatch {
name: c.name.span,
expected,
got,
});
}
}

Expand Down Expand Up @@ -1113,11 +1113,11 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
.inner
.equivalent(&ctx.module.types[init_ty].inner, &ctx.module.types)
{
return Err(Error::InitializationTypeMismatch(
l.name.span,
ctx.format_type(ty),
ctx.format_type(init_ty),
));
return Err(Error::InitializationTypeMismatch {
name: l.name.span,
expected: ctx.format_type(ty),
got: ctx.format_type(init_ty),
});
}
}

Expand Down Expand Up @@ -1152,11 +1152,11 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
.inner
.equivalent(initializer_ty, &ctx.module.types)
{
return Err(Error::InitializationTypeMismatch(
v.name.span,
ctx.format_type(explicit),
ctx.format_typeinner(initializer_ty),
));
return Err(Error::InitializationTypeMismatch {
name: v.name.span,
expected: ctx.format_type(explicit),
got: ctx.format_typeinner(initializer_ty),
});
}
explicit
}
Expand Down

0 comments on commit 528bca7

Please sign in to comment.