diff --git a/src/tint/ast/array.cc b/src/tint/ast/array.cc index cd1fc26783..988dfaf031 100644 --- a/src/tint/ast/array.cc +++ b/src/tint/ast/array.cc @@ -56,11 +56,14 @@ std::string Array::FriendlyName(const SymbolTable& symbols) const { out << "@stride(" << stride->stride << ") "; } } - out << "array<" << type->FriendlyName(symbols); - if (!IsRuntimeArray()) { - out << ", " << SizeExprToString(count, symbols); + out << "array"; + if (type) { + out << "<" << type->FriendlyName(symbols); + if (count) { + out << ", " << SizeExprToString(count, symbols); + } + out << ">"; } - out << ">"; return out.str(); } diff --git a/src/tint/ast/array.h b/src/tint/ast/array.h index ccc31ab229..6ad1cbc468 100644 --- a/src/tint/ast/array.h +++ b/src/tint/ast/array.h @@ -35,9 +35,9 @@ class Array final : public Castable { /// @param nid the unique node identifier /// @param src the source of this node /// @param subtype the type of the array elements - /// @param count the number of elements in the array. nullptr represents a - /// runtime-sized array. + /// @param count the number of elements in the array /// @param attributes the array attributes + /// @note a runtime-sized array is represented by a null count and a non-null type Array(ProgramID pid, NodeID nid, const Source& src, @@ -50,7 +50,7 @@ class Array final : public Castable { /// @returns true if this is a runtime array. /// i.e. the size is determined at runtime - bool IsRuntimeArray() const { return count == nullptr; } + bool IsRuntimeArray() const { return type != nullptr && count == nullptr; } /// @param symbols the program's symbol table /// @returns the name for this type that closely resembles how it would be diff --git a/src/tint/ast/array_test.cc b/src/tint/ast/array_test.cc index f396e0c79d..f8d469b9ae 100644 --- a/src/tint/ast/array_test.cc +++ b/src/tint/ast/array_test.cc @@ -42,6 +42,14 @@ TEST_F(AstArrayTest, CreateRuntimeArray) { EXPECT_TRUE(arr->IsRuntimeArray()); } +TEST_F(AstArrayTest, CreateInferredTypeArray) { + auto* arr = create(nullptr, nullptr, AttributeList{}); + EXPECT_EQ(arr->type, nullptr); + EXPECT_EQ(arr->count, nullptr); + EXPECT_TRUE(arr->Is()); + EXPECT_FALSE(arr->IsRuntimeArray()); +} + TEST_F(AstArrayTest, FriendlyName_RuntimeSized) { auto* i32 = create(); auto* arr = create(i32, nullptr, AttributeList{}); @@ -66,5 +74,15 @@ TEST_F(AstArrayTest, FriendlyName_WithStride) { EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(32) array"); } +TEST_F(AstArrayTest, FriendlyName_InferredTypeAndCount) { + auto* arr = create(nullptr, nullptr, AttributeList{}); + EXPECT_EQ(arr->FriendlyName(Symbols()), "array"); +} + +TEST_F(AstArrayTest, FriendlyName_InferredTypeAndCount_WithStrize) { + auto* arr = create(nullptr, nullptr, AttributeList{create(32u)}); + EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(32) array"); +} + } // namespace } // namespace tint::ast