diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index e971d50425..b3142a2e8d 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -872,7 +872,7 @@ bool GeneratorImpl::EmitContinue(ast::ContinueStatement*) { } bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) { - if (expr->type()->Is()) { + if (expr->type()->IsAnyOf()) { out_ << "{"; } else { if (!EmitType(expr->type(), "")) { @@ -901,7 +901,7 @@ bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) { } } - if (expr->type()->Is()) { + if (expr->type()->IsAnyOf()) { out_ << "}"; } else { out_ << ")"; diff --git a/src/writer/msl/generator_impl_constructor_test.cc b/src/writer/msl/generator_impl_constructor_test.cc index 04bb0ad996..5d43ca869b 100644 --- a/src/writer/msl/generator_impl_constructor_test.cc +++ b/src/writer/msl/generator_impl_constructor_test.cc @@ -154,8 +154,29 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) { "float3(7.0f, 8.0f, 9.0f)}"); } -// TODO(dsinclair): Add struct constructor test. -TEST_F(MslGeneratorImplTest, DISABLED_EmitConstructor_Type_Struct) {} +TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Struct) { + auto* struct_ty = Structure("S", + ast::StructMemberList{ + Member("a", ty.f32()), + Member("b", ty.u32()), + Member("c", ty.vec4()), + }, + ast::DecorationList{}); + + ast::ExpressionList struct_values; + struct_values.push_back(Expr(0.f)); + struct_values.push_back(Expr(42u)); + struct_values.push_back(Construct( + ty.vec4(), + ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f), Expr(4.f)})); + + auto* expr = Construct(struct_ty, struct_values); + + GeneratorImpl& gen = Build(); + + ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error(); + EXPECT_EQ(gen.result(), "{0.0f, 42u, float4(1.0f, 2.0f, 3.0f, 4.0f)}"); +} } // namespace } // namespace msl