diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 9fd861afe6..910850f248 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -892,23 +892,15 @@ bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) { out_ << "("; } - // If the type constructor is empty then we need to construct with the zero - // value for all components. - if (expr->values().empty()) { - if (!EmitZeroValue(type)) { - return false; + bool first = true; + for (auto* e : expr->values()) { + if (!first) { + out_ << ", "; } - } else { - bool first = true; - for (auto* e : expr->values()) { - if (!first) { - out_ << ", "; - } - first = false; + first = false; - if (!EmitExpression(e)) { - return false; - } + if (!EmitExpression(e)) { + return false; } } diff --git a/src/writer/msl/generator_impl_constructor_test.cc b/src/writer/msl/generator_impl_constructor_test.cc index aa76ded225..97f5543a6a 100644 --- a/src/writer/msl/generator_impl_constructor_test.cc +++ b/src/writer/msl/generator_impl_constructor_test.cc @@ -112,7 +112,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec_Empty) { GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.Generate()) << gen.error(); - EXPECT_THAT(gen.result(), HasSubstr("float3(0.0f)")); + EXPECT_THAT(gen.result(), HasSubstr("float3()")); } TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) { @@ -137,7 +137,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat_Empty) { GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.Generate()) << gen.error(); - EXPECT_THAT(gen.result(), HasSubstr("float4x4(0.0f)")); + EXPECT_THAT(gen.result(), HasSubstr("float4x4()")); } TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) { @@ -155,10 +155,10 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) { TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Struct) { auto* str = Structure("S", { - Member("a", ty.i32()), - Member("b", ty.f32()), - Member("c", ty.vec3()), - }); + Member("a", ty.i32()), + Member("b", ty.f32()), + Member("c", ty.vec3()), + }); WrapInFunction(Construct(str, 1, 2.0f, vec3(3, 4, 5))); @@ -168,6 +168,18 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Struct) { EXPECT_THAT(gen.result(), HasSubstr("{1, 2.0f, int3(3, 4, 5)}")); } +TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Struct_Empty) { + auto* str = Structure("S", {}); + + WrapInFunction(Construct(str)); + + GeneratorImpl& gen = Build(); + + ASSERT_TRUE(gen.Generate()) << gen.error(); + EXPECT_THAT(gen.result(), HasSubstr("{}")); + EXPECT_THAT(gen.result(), Not(HasSubstr("{{}}"))); +} + } // namespace } // namespace msl } // namespace writer diff --git a/src/writer/msl/generator_impl_function_test.cc b/src/writer/msl/generator_impl_function_test.cc index 83ffab058d..5cf1eb85d8 100644 --- a/src/writer/msl/generator_impl_function_test.cc +++ b/src/writer/msl/generator_impl_function_test.cc @@ -214,7 +214,7 @@ struct tint_symbol_3 { }; vertex tint_symbol vert_main() { - Interface const tint_symbol_1 = {0.5f, 0.25f, float4(0.0f)}; + Interface const tint_symbol_1 = {0.5f, 0.25f, float4()}; return {tint_symbol_1.col1, tint_symbol_1.col2, tint_symbol_1.pos}; } diff --git a/src/writer/msl/generator_impl_variable_decl_statement_test.cc b/src/writer/msl/generator_impl_variable_decl_statement_test.cc index 3ff3388f8b..487a5a8bcf 100644 --- a/src/writer/msl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/msl/generator_impl_variable_decl_statement_test.cc @@ -48,7 +48,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error(); - EXPECT_EQ(gen.result(), " float const a = float(0.0f);\n"); + EXPECT_EQ(gen.result(), " float const a = float();\n"); } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) { @@ -150,7 +150,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) { GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error(); - EXPECT_EQ(gen.result(), R"(float3 a = float3(0.0f); + EXPECT_EQ(gen.result(), R"(float3 a = float3(); )"); } diff --git a/test/samples/simple.wgsl.expected.msl b/test/samples/simple.wgsl.expected.msl index a132f06191..8a04d0c330 100644 --- a/test/samples/simple.wgsl.expected.msl +++ b/test/samples/simple.wgsl.expected.msl @@ -9,7 +9,7 @@ void bar() { } fragment tint_symbol_1 tint_symbol() { - float2 a = float2(0.0f); + float2 a = float2(); bar(); return {float4(0.400000006f, 0.400000006f, 0.800000012f, 1.0f)}; }