fix(naga): Improve validation of non-constructible types (#8873)

* fix(naga): Improve validation of non-constructible types

Fixes #4720
Fixes the test cases in #7393, but not the issue itself

* Zero-constructing texture_2d is no longer caught by front end.

* Define `TypeInner::is_constructible`; use it in `front::wgsl`.

Add a new method `TypeInner::is_constructible`, that determines
whether WGSL considers a type [constructible]. Use this to generate
errors in the WGSL front end. Assert in validation that it matches the
judgment of `Validator::validate_type`.

[constructible]: https://gpuweb.github.io/gpuweb/wgsl/#constructible-types

---------

Co-authored-by: Jim Blandy <jimb@red-bean.com>
This commit is contained in:
Andy LeisersonandJim Blandy authored and GitHub committed 2026-02-18 11:08:53 -08:00
1 parent 8f50bb9d98
commit c4365b9818
10 files changed
+597 -93

No files matched your search

+1
View File
@@ -130,6 +130,7 @@ By @cwfitzgerald in [#8999](https://github.com/gfx-rs/wgpu/pull/8999).
- Check that if the shader outputs `frag_depth`, then the pipeline must have a depth attachment. By @andyleiserson in [#8856](https://github.com/gfx-rs/wgpu/pull/8856).
- Fix incorrect acceptance of some swizzle selectors that are not valid for their operand, e.g. `const v = vec2<i32>(); let r = v.xyz`. By @andyleiserson in [#8949](https://github.com/gfx-rs/wgpu/pull/8949).
- Fixed calculation of the total number of bindings in a pipeline layout when validating against device limits. By @andyleiserson in [#8997](https://github.com/gfx-rs/wgpu/pull/8997).
- Reject non-constructible types (runtime- and override-sized arrays, and structs containing non-constructible types) in more places where they should not be allowed. By @andyleiserson in [#8873](https://github.com/gfx-rs/wgpu/pull/8873).
#### Vulkan
- Fixed a variety of mesh shader SPIR-V writer issues from the original implementation. By @inner-daemons in [#8756](https://github.com/gfx-rs/wgpu/pull/8756)
+6 -1
View File
@@ -378,13 +378,18 @@ webgpu:shader,validation,expression,call,builtin,textureNumSamples:*
fails-if(vulkan) webgpu:shader,validation,expression,call,builtin,textureSampleBaseClampToEdge:*
webgpu:shader,validation,expression,call,builtin,textureStore:*
webgpu:shader,validation,expression,call,builtin,trunc:*
// FAIL: others in `value_constructor` due to https://github.com/gfx-rs/wgpu/issues/4720, possibly more
webgpu:shader,validation,expression,call,builtin,value_constructor:array_value:*
webgpu:shader,validation,expression,call,builtin,value_constructor:array_zero_value:*
webgpu:shader,validation,expression,call,builtin,value_constructor:matrix_zero_value:*
webgpu:shader,validation,expression,call,builtin,value_constructor:must_use:ctor="mat4x4";use=true
webgpu:shader,validation,expression,call,builtin,value_constructor:partial_eval:*
webgpu:shader,validation,expression,call,builtin,value_constructor:scalar_value:*
webgpu:shader,validation,expression,call,builtin,value_constructor:scalar_zero_value:*
webgpu:shader,validation,expression,call,builtin,value_constructor:struct_value:*
webgpu:shader,validation,expression,call,builtin,value_constructor:struct_zero_value:*
webgpu:shader,validation,expression,call,builtin,value_constructor:vector_copy:*
webgpu:shader,validation,expression,call,builtin,value_constructor:vector_elementwise:*
webgpu:shader,validation,expression,call,builtin,value_constructor:vector_mixed:*
webgpu:shader,validation,expression,call,builtin,value_constructor:vector_splat:*
webgpu:shader,validation,expression,call,builtin,value_constructor:vector_zero_value:*
webgpu:shader,validation,expression,call,builtin,workgroupUniformLoad:*
+35 -30
View File
@@ -152,33 +152,35 @@ impl<'source> Lowerer<'source, '_> {
let expr;
match (components, constructor) {
// Empty constructor
(Components::None, dst_ty) => match dst_ty {
Constructor::Type((result_ty, _)) => {
expr = crate::Expression::ZeroValue(result_ty);
}
Constructor::PartialVector { size } => {
// vec2(), vec3(), vec4() return vectors of abstractInts; the same
// is not true of the similar constructors for matrices or arrays.
// See https://www.w3.org/TR/WGSL/#vec2-builtin et seq.
let result_ty = ctx.module.types.insert(
crate::Type {
name: None,
inner: crate::TypeInner::Vector {
size,
scalar: crate::Scalar::ABSTRACT_INT,
},
// Zero-value constructor with explicit type.
(Components::None, Constructor::Type((result_ty, inner)))
if inner.is_constructible(&ctx.module.types) =>
{
expr = crate::Expression::ZeroValue(result_ty);
}
// Zero-value constructor, vector with type inference
(Components::None, Constructor::PartialVector { size }) => {
// vec2(), vec3(), vec4() return vectors of abstractInts; the same
// is not true of the similar constructors for matrices or arrays.
// See https://www.w3.org/TR/WGSL/#vec2-builtin et seq.
let result_ty = ctx.module.types.insert(
crate::Type {
name: None,
inner: crate::TypeInner::Vector {
size,
scalar: crate::Scalar::ABSTRACT_INT,
},
span,
);
expr = crate::Expression::ZeroValue(result_ty);
}
Constructor::PartialMatrix { .. } | Constructor::PartialArray => {
// We have no arguments from which to infer the result type, so
// partial constructors aren't acceptable here.
return Err(Box::new(Error::TypeNotInferable(ty_span)));
}
},
},
span,
);
expr = crate::Expression::ZeroValue(result_ty);
}
// Zero-value constructor, matrix or array with type inference
(Components::None, Constructor::PartialMatrix { .. } | Constructor::PartialArray) => {
// We have no arguments from which to infer the result type, so
// partial constructors aren't acceptable here.
return Err(Box::new(Error::TypeNotInferable(ty_span)));
}
// Scalar constructor & conversion (scalar -> scalar)
(
@@ -530,8 +532,11 @@ impl<'source> Lowerer<'source, '_> {
expr = crate::Expression::Compose { ty, components };
}
// Array constructor, explicit type
(components, Constructor::Type((ty, &crate::TypeInner::Array { base, .. }))) => {
// Array constructor, explicit type.
(
components,
Constructor::Type((ty, inner @ &crate::TypeInner::Array { base, .. })),
) if inner.is_constructible(&ctx.module.types) => {
let mut components = components.into_components_vec();
ctx.try_automatic_conversions_slice(&mut components, &Tr::Handle(base), ty_span)?;
expr = crate::Expression::Compose { ty, components };
@@ -540,8 +545,8 @@ impl<'source> Lowerer<'source, '_> {
// Struct constructor
(
components,
Constructor::Type((ty, &crate::TypeInner::Struct { ref members, .. })),
) => {
Constructor::Type((ty, inner @ &crate::TypeInner::Struct { ref members, .. })),
) if inner.is_constructible(&ctx.module.types) => {
let mut components = components.into_components_vec();
let struct_ty_span = ctx.module.types.get_span(ty);
+15 -1
View File
@@ -1811,7 +1811,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
let mut ectx = ctx.as_expression(block, &mut emitter);
let (_ty, initializer) = self.type_and_init(
let (ty, initializer) = self.type_and_init(
l.name,
Some(l.init),
explicit_ty,
@@ -1819,6 +1819,20 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
&mut ectx,
)?;
// We have this special check here for `let` declarations because the
// validator doesn't check them (they are comingled with other things in
// `named_expressions`; see <https://github.com/gfx-rs/wgpu/issues/7393>).
// The check could go in `type_and_init`, but then we'd have to
// distinguish whether override-sized is allowed. The error ought to use
// the type's span, but `module.types.get_span(ty)` is `Span::UNDEFINED`
// (see <https://github.com/gfx-rs/wgpu/issues/7951>).
if ctx.module.types[ty]
.inner
.is_dynamically_sized(&ctx.module.types)
{
return Err(Box::new(Error::TypeNotConstructible(l.name.span)));
}
// We passed `Some()` to `type_and_init`, so we
// will get a lowered initializer expression back.
let initializer =
+38 -1
View File
@@ -344,10 +344,18 @@ impl crate::TypeInner {
left.as_ref().unwrap_or(self) == right.as_ref().unwrap_or(rhs)
}
/// Returns true if `self` is runtime- or override-sized.
pub fn is_dynamically_sized(&self, types: &crate::UniqueArena<crate::Type>) -> bool {
use crate::TypeInner as Ti;
match *self {
Ti::Array { size, .. } => size == crate::ArraySize::Dynamic,
Ti::Array {
size: crate::ArraySize::Constant(_),
..
} => false,
Ti::Array {
size: crate::ArraySize::Pending(_) | crate::ArraySize::Dynamic,
..
} => true,
Ti::Struct { ref members, .. } => members
.last()
.map(|last| types[last.ty].inner.is_dynamically_sized(types))
@@ -356,6 +364,35 @@ impl crate::TypeInner {
}
}
/// Returns true if `self` is a constructible type.
pub fn is_constructible(&self, types: &crate::UniqueArena<crate::Type>) -> bool {
use crate::TypeInner as Ti;
match *self {
Ti::Array { base, size, .. } => {
let fixed_size = match size {
ir::ArraySize::Constant(_) => true,
ir::ArraySize::Pending(_) | ir::ArraySize::Dynamic => false,
};
fixed_size && types[base].inner.is_constructible(types)
}
Ti::Struct { ref members, .. } => members
.iter()
.all(|member| types[member.ty].inner.is_constructible(types)),
Ti::Atomic(_)
| Ti::Pointer { .. }
| Ti::ValuePointer { .. }
| Ti::Image { .. }
| Ti::Sampler { .. }
| Ti::AccelerationStructure { .. }
| Ti::BindingArray { .. } => false,
Ti::Scalar(_)
| Ti::Vector { .. }
| Ti::Matrix { .. }
| Ti::RayQuery { .. }
| Ti::CooperativeMatrix { .. } => true,
}
}
pub const fn components(&self) -> Option<u32> {
Some(match *self {
Self::Vector { size, .. } => size as u32,
+5 -6
View File
@@ -1,14 +1,11 @@
use super::{compose::validate_compose, FunctionInfo, ModuleInfo, ShaderStages, TypeFlags};
use crate::arena::UniqueArena;
use crate::valid::expression::builtin::validate_zero_value;
use crate::{
arena::Handle,
proc::OverloadSet as _,
proc::{IndexableLengthError, ResolveError},
};
pub mod builtin;
#[derive(Clone, Debug, thiserror::Error)]
#[cfg_attr(test, derive(PartialEq))]
pub enum ExpressionError {
@@ -38,8 +35,8 @@ pub enum ExpressionError {
InvalidSwizzleComponent(crate::SwizzleComponent, crate::VectorSize),
#[error(transparent)]
Compose(#[from] super::ComposeError),
#[error(transparent)]
ZeroValue(#[from] super::ZeroValueError),
#[error("Cannot construct zero value of {0:?} because it is not a constructible type")]
InvalidZeroValue(Handle<crate::Type>),
#[error(transparent)]
IndexableLength(#[from] IndexableLengthError),
#[error("Operation {0:?} can't work with {1:?}")]
@@ -460,7 +457,9 @@ impl super::Validator {
}
E::Constant(_) | E::Override(_) => ShaderStages::all(),
E::ZeroValue(ty) => {
validate_zero_value(ty, module.to_ctx())?;
if !mod_info[ty].contains(TypeFlags::CONSTRUCTIBLE) {
return Err(ExpressionError::InvalidZeroValue(ty));
}
ShaderStages::all()
}
E::Compose { ref components, ty } => {
-26
View File
@@ -1,26 +0,0 @@
use crate::arena::Handle;
#[derive(Clone, Debug, thiserror::Error)]
#[cfg_attr(test, derive(PartialEq))]
pub enum ZeroValueError {
#[error("ZeroValue construction of runtime-sized array is not allowed")]
RuntimeSizedArray,
}
pub fn validate_zero_value(
self_ty_handle: Handle<crate::Type>,
gctx: crate::proc::GlobalCtx,
) -> Result<(), ZeroValueError> {
use crate::TypeInner as Ti;
match gctx.types[self_ty_handle].inner {
Ti::Array {
base: _,
size: crate::ArraySize::Dynamic,
stride: _,
} => {
log::error!("Constructing zero value of runtime-sized array");
Err(ZeroValueError::RuntimeSizedArray)
}
_ => Ok(()),
}
}
+4 -1
View File
@@ -27,7 +27,6 @@ use crate::{
use crate::span::{AddSpan as _, WithSpan};
pub use analyzer::{ExpressionInfo, FunctionInfo, GlobalUse, Uniformity, UniformityRequirements};
pub use compose::ComposeError;
pub use expression::builtin::ZeroValueError;
pub use expression::{check_literal_value, LiteralError};
pub use expression::{ConstExpressionError, ExpressionError};
pub use function::{CallError, FunctionError, LocalVariableError, SubgroupError};
@@ -771,6 +770,10 @@ impl Validator {
}
.with_span_handle(handle, &module.types)
})?;
debug_assert!(
ty_info.flags.contains(TypeFlags::CONSTRUCTIBLE)
== module.types[handle].inner.is_constructible(&module.types)
);
mod_info.type_flags.push(ty_info.flags);
self.types[handle.index()] = ty_info;
}
+397 -21
View File
@@ -781,32 +781,408 @@ fn bad_texture_dimensions_level() {
assert!(validate("1").is_ok());
}
// Adds IR for `override len: u32` and the type `array<u32, len>`.
fn make_override_array(module: &mut ir::Module) -> naga::Handle<ir::Type> {
let span = naga::Span::default();
let ty_u32 = module.types.insert(
ir::Type {
name: Some("u32".into()),
inner: ir::TypeInner::Scalar(Scalar::U32),
},
span,
);
let len = module.overrides.append(
ir::Override {
name: Some("len".into()),
id: None,
ty: ty_u32,
init: None,
},
span,
);
module.types.insert(
ir::Type {
name: Some("array<u32, len>".into()),
inner: ir::TypeInner::Array {
base: ty_u32,
size: ir::ArraySize::Pending(len),
stride: 4,
},
},
span,
)
}
// Adds IR for type `array<u32>`.
fn make_runtime_array(module: &mut ir::Module) -> naga::Handle<ir::Type> {
let span = naga::Span::default();
let ty_u32 = module.types.insert(
ir::Type {
name: Some("u32".into()),
inner: ir::TypeInner::Scalar(Scalar::U32),
},
span,
);
module.types.insert(
ir::Type {
name: Some("array<u32>".into()),
inner: ir::TypeInner::Array {
base: ty_u32,
size: ir::ArraySize::Dynamic,
stride: 4,
},
},
span,
)
}
// Adds a local variable `var x: ty = ty();`.
fn make_zero_value_local_variable(fun: &mut Function, ty: naga::Handle<ir::Type>) {
let span = naga::Span::default();
let ex_zero = fun.expressions.append(Expression::ZeroValue(ty), span);
fun.local_variables.append(
naga::LocalVariable {
name: Some("x".into()),
ty,
init: Some(ex_zero),
},
span,
);
}
#[test]
fn zero_value_dyn_array_error() {
let source = r#"
@compute @workgroup_size(1)
fn main() {
let a = array<f32>();
}
"#;
let module = naga::front::wgsl::parse_str(source).expect("module should parse");
fn invalid_local_var_override_sized_array() {
// Similar to a test in wgsl_errors::invalid_local_vars.
// ```
// override len: u32;
// var<workgroup> arr: array<u32, len>;
// fn f() {
// var x: array<u32, len> = arr;
// }
// ```
let span = naga::Span::default();
let mut module = ir::Module::default();
let ty_array = make_override_array(&mut module);
let var_arr = module.global_variables.append(
naga::GlobalVariable {
name: Some("arr".into()),
space: naga::AddressSpace::WorkGroup,
binding: None,
ty: ty_array,
init: None,
},
span,
);
let mut fun = Function {
name: Some("f".into()),
..Default::default()
};
let ex_global = fun
.expressions
.append(Expression::GlobalVariable(var_arr), span);
let ex_load = fun
.expressions
.append(Expression::Load { pointer: ex_global }, span);
fun.local_variables.append(
naga::LocalVariable {
name: Some("x".into()),
ty: ty_array,
init: Some(ex_load),
},
span,
);
module.functions.append(fun, span);
let err = valid::Validator::new(Default::default(), valid::Capabilities::all())
.validate(&module)
.map_err(|err| err.into_inner()); // discard spans
.expect_err("module should be invalid")
.into_inner();
assert!(matches!(
err,
Err(naga::valid::ValidationError::EntryPoint {
stage: _,
name: _,
source: naga::valid::EntryPointError::Function(
naga::valid::FunctionError::Expression {
handle: _,
source: naga::valid::ExpressionError::ZeroValue(
naga::valid::ZeroValueError::RuntimeSizedArray
)
}
)
})
valid::ValidationError::Function {
source: valid::FunctionError::LocalVariable {
name: local_var_name,
source: valid::LocalVariableError::InvalidType(_),
..
},
..
} if local_var_name == "x"
));
}
#[test]
fn invalid_zero_value_runtime_array() {
// Similar to a test in wgsl_errors::invalid_zero_value_constructors.
// ```
// fn main() {
// var x = array<u32>();
// }
// ```
let span = naga::Span::default();
let mut module = ir::Module::default();
let ty_array = make_runtime_array(&mut module);
let mut fun = Function {
name: Some("f".into()),
..Default::default()
};
make_zero_value_local_variable(&mut fun, ty_array);
module.functions.append(fun, span);
let err = valid::Validator::new(Default::default(), valid::Capabilities::all())
.validate(&module)
.expect_err("module should be invalid")
.into_inner();
assert!(matches!(
err,
valid::ValidationError::Function {
source: valid::FunctionError::LocalVariable {
name: local_var_name,
source: valid::LocalVariableError::InvalidType(_),
..
},
..
} if local_var_name == "x"
));
}
#[test]
fn invalid_zero_value_override_array() {
// Similar to a test in wgsl_errors::invalid_zero_value_constructors.
// ```
// override len: u32;
// fn main() {
// var x = array<u32, len>();
// }
// ```
let span = naga::Span::default();
let mut module = ir::Module::default();
let ty_array = make_override_array(&mut module);
let mut fun = Function {
name: Some("f".into()),
..Default::default()
};
make_zero_value_local_variable(&mut fun, ty_array);
module.functions.append(fun, span);
let err = valid::Validator::new(Default::default(), valid::Capabilities::all())
.validate(&module)
.expect_err("module should be invalid")
.into_inner();
assert!(matches!(
err,
valid::ValidationError::Function {
source: valid::FunctionError::LocalVariable {
name: local_var_name,
source: valid::LocalVariableError::InvalidType(_),
..
},
..
} if local_var_name == "x"
));
}
#[test]
fn invalid_zero_value_texture() {
// Similar to a test in wgsl_errors::invalid_zero_value_constructors.
// ```
// fn main() {
// var x = texture_2d<f32>();
// }
// ```
use naga::{ImageClass, ImageDimension, Module, Type, TypeInner};
let span = naga::Span::default();
let mut module = Module::default();
let ty_texture = module.types.insert(
Type {
name: Some("texture_2d<f32>".into()),
inner: TypeInner::Image {
dim: ImageDimension::D2,
arrayed: false,
class: ImageClass::Sampled {
kind: naga::ScalarKind::Float,
multi: false,
},
},
},
span,
);
let mut fun = Function {
name: Some("f".into()),
..Default::default()
};
make_zero_value_local_variable(&mut fun, ty_texture);
module.functions.append(fun, span);
let err = valid::Validator::new(Default::default(), valid::Capabilities::all())
.validate(&module)
.expect_err("module should be invalid")
.into_inner();
assert!(matches!(
err,
valid::ValidationError::Function {
source: valid::FunctionError::LocalVariable {
name: local_var_name,
source: valid::LocalVariableError::InvalidType(_),
..
},
..
} if local_var_name == "x"
));
}
/// Test for non-zero-value runtime-sized array constructor.
#[test]
fn invalid_constructor_runtime_array() {
// Similar to a test in wgsl_errors::invalid_zero_value_constructors.
// ```
// fn main() {
// var x = array<u32>(0, 1, 2);
// }
// ```
let span = naga::Span::default();
let mut module = ir::Module::default();
let ty_array = make_runtime_array(&mut module);
let mut fun = Function {
name: Some("f".into()),
..Default::default()
};
// Create component expressions
let ex_0 = fun
.expressions
.append(Expression::Literal(naga::Literal::U32(0)), span);
let ex_1 = fun
.expressions
.append(Expression::Literal(naga::Literal::U32(1)), span);
let ex_2 = fun
.expressions
.append(Expression::Literal(naga::Literal::U32(2)), span);
// Create a Compose expression to construct the array
let ex_compose = fun.expressions.append(
Expression::Compose {
ty: ty_array,
components: vec![ex_0, ex_1, ex_2],
},
span,
);
fun.local_variables.append(
naga::LocalVariable {
name: Some("x".into()),
ty: ty_array,
init: Some(ex_compose),
},
span,
);
module.functions.append(fun, span);
let err = valid::Validator::new(Default::default(), valid::Capabilities::all())
.validate(&module)
.expect_err("module should be invalid")
.into_inner();
assert!(matches!(
err,
valid::ValidationError::Function {
source: valid::FunctionError::LocalVariable {
name: local_var_name,
source: valid::LocalVariableError::InvalidType(_),
..
},
..
} if local_var_name == "x"
));
}
#[test]
fn invalid_constructor_unsized_struct() {
// Similar to a test in wgsl_errors::invalid_zero_value_constructors:
// ```
// struct Unsized { data: array<f32> }
// fn main() {
// var x: Unsized = Unsized();
// }
// ```
use naga::{Module, StructMember, Type, TypeInner};
let span = naga::Span::default();
let mut module = Module::default();
let ty_array = make_runtime_array(&mut module);
let ty_unsized = module.types.insert(
Type {
name: Some("Unsized".into()),
inner: TypeInner::Struct {
members: vec![StructMember {
name: Some("data".into()),
ty: ty_array,
binding: None,
offset: 0,
}],
span: 4,
},
},
span,
);
let mut fun = Function {
name: Some("main".into()),
..Default::default()
};
make_zero_value_local_variable(&mut fun, ty_unsized);
module.functions.append(fun, span);
let err = valid::Validator::new(Default::default(), valid::Capabilities::all())
.validate(&module)
.expect_err("module should be invalid")
.into_inner();
assert!(matches!(
err,
valid::ValidationError::Function {
source: valid::FunctionError::LocalVariable {
source: valid::LocalVariableError::InvalidType(_),
..
},
..
},
));
}
+96 -6
View File
@@ -2224,10 +2224,10 @@ fn invalid_local_vars() {
var not_okay: ptr<storage, array<f32>> = &(*okay).data;
}
":
Err(naga::valid::ValidationError::Function {
source: naga::valid::FunctionError::LocalVariable {
Err(valid::ValidationError::Function {
source: valid::FunctionError::LocalVariable {
name: local_var_name,
source: naga::valid::LocalVariableError::InvalidType(_),
source: valid::LocalVariableError::InvalidType(_),
..
},
..
@@ -2241,16 +2241,106 @@ fn invalid_local_vars() {
var x: atomic<u32>;
}
":
Err(naga::valid::ValidationError::Function {
source: naga::valid::FunctionError::LocalVariable {
Err(valid::ValidationError::Function {
source: valid::FunctionError::LocalVariable {
name: local_var_name,
source: naga::valid::LocalVariableError::InvalidType(_),
source: valid::LocalVariableError::InvalidType(_),
..
},
..
})
if local_var_name == "x"
}
// Rejected in statement lowering
// There is a similar validator test in `validation.rs`.
check(
"
override len: u32;
var<workgroup> arr: array<u32, len>;
fn f() {
let x: array<u32, len> = arr;
}
",
r#"error: type `x` is not constructible
┌─ wgsl:5:17
│
5 │ let x: array<u32, len> = arr;
│ ^ type is not constructible
"#,
);
}
#[test]
fn invalid_zero_value_constructors() {
// There are similar validator tests in `validation.rs`.
// Rejected in constructor lowering
check(
"
fn f() {
let x = array<u32>();
}
",
r#"error: type `array<u32>` is not constructible
┌─ wgsl:3:21
│
3 │ let x = array<u32>();
│ ^^^^^^^^^^ type is not constructible
"#,
);
// Rejected in constructor lowering
check(
"
override len: u32;
fn f() {
let x = array<u32, len>();
}
",
r#"error: type `array<u32, len>` is not constructible
┌─ wgsl:4:21
│
4 │ let x = array<u32, len>();
│ ^^^^^^^^^^^^^^^ type is not constructible
"#,
);
// Rejected in constructor lowering
check(
"
fn f() {
let x = array<u32>(0, 1, 2);
}
",
r#"error: type `array<u32>` is not constructible
┌─ wgsl:3:21
│
3 │ let x = array<u32>(0, 1, 2);
│ ^^^^^^^^^^ type is not constructible
"#,
);
// Rejected in constructor lowering
check(
"
struct Unsized { data: array<f32> }
fn main() {
var not_okay: Unsized = Unsized();
}
",
r#"error: type `Unsized` is not constructible
┌─ wgsl:4:37
│
4 │ var not_okay: Unsized = Unsized();
│ ^^^^^^^ type is not constructible
"#,
);
}
#[test]