Give front::wgsl::Error::InitializationTypeMismatch named fields.

This commit is contained in:
Jim Blandy
2023-10-21 17:03:19 -07:00
committed by Teodor Tanasoaia
parent 946745d38f
commit 528bca75f7
2 changed files with 26 additions and 22 deletions

View File

@@ -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),
@@ -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![],
}

View File

@@ -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,
});
}
}
@@ -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),
});
}
}
@@ -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
}