diff --git a/src/tint/sem/array_test.cc b/src/tint/sem/array_test.cc index d6ce9cd021..e6efff22eb 100644 --- a/src/tint/sem/array_test.cc +++ b/src/tint/sem/array_test.cc @@ -125,5 +125,15 @@ TEST_F(ArrayTest, FriendlyNameStaticSizedNonImplicitStride) { EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(8) array"); } +TEST_F(ArrayTest, IsConstructable) { + auto* fixed_sized = create(create(), ConstantArrayCount{2u}, 4u, 8u, 32u, 16u); + auto* override_sized = create(create(), OverrideArrayCount{}, 4u, 8u, 32u, 16u); + auto* runtime_sized = create(create(), RuntimeArrayCount{}, 4u, 8u, 32u, 16u); + + EXPECT_TRUE(fixed_sized->IsConstructible()); + EXPECT_FALSE(override_sized->IsConstructible()); + EXPECT_FALSE(runtime_sized->IsConstructible()); +} + } // namespace } // namespace tint::sem diff --git a/src/tint/sem/struct_test.cc b/src/tint/sem/struct_test.cc index 97465899e7..12ded84d1e 100644 --- a/src/tint/sem/struct_test.cc +++ b/src/tint/sem/struct_test.cc @@ -124,5 +124,38 @@ TEST_F(StructTest, Location) { EXPECT_FALSE(sem->Members()[1]->Location().has_value()); } +TEST_F(StructTest, IsConstructable) { + auto* inner = // + Structure("Inner", utils::Vector{ + Member("a", ty.i32()), + Member("b", ty.u32()), + Member("c", ty.f32()), + Member("d", ty.vec3()), + Member("e", ty.mat4x2()), + }); + + auto* outer = Structure("Outer", utils::Vector{ + Member("inner", ty.type_name("Inner")), + Member("a", ty.i32()), + }); + + auto* outer_runtime_sized_array = + Structure("OuterRuntimeSizedArray", utils::Vector{ + Member("inner", ty.type_name("Inner")), + Member("a", ty.i32()), + Member("runtime_sized_array", ty.array()), + }); + auto p = Build(); + ASSERT_TRUE(p.IsValid()) << p.Diagnostics().str(); + + auto* sem_inner = p.Sem().Get(inner); + auto* sem_outer = p.Sem().Get(outer); + auto* sem_outer_runtime_sized_array = p.Sem().Get(outer_runtime_sized_array); + + EXPECT_TRUE(sem_inner->IsConstructible()); + EXPECT_TRUE(sem_outer->IsConstructible()); + EXPECT_FALSE(sem_outer_runtime_sized_array->IsConstructible()); +} + } // namespace } // namespace tint::sem