Fix WGSL vector splat constructor's type handling

Previously the constructor just used the type of the scalar argument
regardless of whether or not it actually matched the vector splat
constructors target type. This resulted in e.g. `vec2<f32>(0)`
erroneously getting the type of a bi-vector of Sints with width 4.

Now the splat constructor checks that the kind and width of the scalar
argument is the same as that of the target specified in the
constructor's type parameter.
This commit is contained in:
Hans Christian Schmitz
2021-08-18 08:06:04 +02:00
committed by Dzmitry Malyshau
parent 7a45d73465
commit 01250b85fe
2 changed files with 29 additions and 6 deletions

View File

@@ -1746,12 +1746,19 @@ impl Parser {
ty_resolution.inner_with(ctx.types),
ctx.typifier.get(last_component, ctx.types),
) {
(&crate::TypeInner::Vector { size, .. }, &crate::TypeInner::Scalar { .. }) => {
crate::Expression::Splat {
size,
value: last_component,
}
}
(
&crate::TypeInner::Vector {
size, kind, width, ..
},
&crate::TypeInner::Scalar {
kind: arg_kind,
width: arg_width,
..
},
) if arg_kind == kind && arg_width == width => crate::Expression::Splat {
size,
value: last_component,
},
(
&crate::TypeInner::Scalar { kind, width, .. },
&crate::TypeInner::Scalar { .. },

View File

@@ -65,6 +65,22 @@ fn parse_type_cast() {
",
)
.unwrap();
parse_str(
"
fn main() {
let x: vec2<f32> = vec2<f32>(0.0);
}
",
)
.unwrap();
assert!(parse_str(
"
fn main() {
let x: vec2<f32> = vec2<f32>(0);
}
",
)
.is_err());
}
#[test]