diff --git a/src/tint/writer/wgsl/generator_impl.cc b/src/tint/writer/wgsl/generator_impl.cc index 6ca708349a..f3129c0e61 100644 --- a/src/tint/writer/wgsl/generator_impl.cc +++ b/src/tint/writer/wgsl/generator_impl.cc @@ -382,19 +382,22 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) { } } - out << "array<"; - if (!EmitType(out, ary->type)) { - return false; - } + out << "array"; + if (ary->type) { + out << "<"; + TINT_DEFER(out << ">"); - if (!ary->IsRuntimeArray()) { - out << ", "; - if (!EmitExpression(out, ary->count)) { + if (!EmitType(out, ary->type)) { return false; } - } - out << ">"; + if (!ary->IsRuntimeArray()) { + out << ", "; + if (!EmitExpression(out, ary->count)) { + return false; + } + } + } return true; }, [&](const ast::Bool*) { diff --git a/src/tint/writer/wgsl/generator_impl_constructor_test.cc b/src/tint/writer/wgsl/generator_impl_constructor_test.cc index 07b10ad2ac..40bf393b28 100644 --- a/src/tint/writer/wgsl/generator_impl_constructor_test.cc +++ b/src/tint/writer/wgsl/generator_impl_constructor_test.cc @@ -174,5 +174,17 @@ TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_Array) { "vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f))")); } +TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_ImplicitArray) { + WrapInFunction(Construct(ty.array(nullptr, nullptr), vec3(1_f, 2_f, 3_f), + vec3(4_f, 5_f, 6_f), vec3(7_f, 8_f, 9_f))); + + GeneratorImpl& gen = Build(); + + ASSERT_TRUE(gen.Generate()) << gen.error(); + EXPECT_THAT(gen.result(), + HasSubstr("array(vec3(1.0f, 2.0f, 3.0f), " + "vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f))")); +} + } // namespace } // namespace tint::writer::wgsl