diff --git a/src/resolver/assignment_validation_test.cc b/src/resolver/assignment_validation_test.cc index 0e0ad423e1..580e5521d0 100644 --- a/src/resolver/assignment_validation_test.cc +++ b/src/resolver/assignment_validation_test.cc @@ -177,7 +177,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignToConstant_Fail) { "12:34 error: cannot assign to const\nnote: 'a' is declared here:"); } -TEST_F(ResolverAssignmentValidationTest, AssignNonStorable_Fail) { +TEST_F(ResolverAssignmentValidationTest, AssignNonConstructible_Handle) { // var a : texture_storage_1d; // var b : texture_storage_1d; // a = b; @@ -203,8 +203,51 @@ TEST_F(ResolverAssignmentValidationTest, AssignNonStorable_Fail) { EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), - "56:78 error: cannot store into a read-only type " - "'texture_storage_1d'"); + "56:78 error: storage type of assignment must be constructible"); +} + +TEST_F(ResolverAssignmentValidationTest, AssignNonConstructible_Atomic) { + // [[block]] struct S { a : atomic; }; + // [[group(0), binding(0)]] var v : S; + // v.a = v.a; + + auto* s = Structure("S", {Member("a", ty.atomic(ty.i32()))}, + {create()}); + Global(Source{{12, 34}}, "v", ty.Of(s), ast::StorageClass::kStorage, + ast::Access::kReadWrite, + ast::DecorationList{ + create(0), + create(0), + }); + + WrapInFunction(Assign(Source{{56, 78}}, MemberAccessor("v", "a"), + MemberAccessor("v", "a"))); + + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), + "56:78 error: storage type of assignment must be constructible"); +} + +TEST_F(ResolverAssignmentValidationTest, AssignNonConstructible_RuntimeArray) { + // [[block]] struct S { a : array; }; + // [[group(0), binding(0)]] var v : S; + // v.a = v.a; + + auto* s = Structure("S", {Member("a", ty.array(ty.f32()))}, + {create()}); + Global(Source{{12, 34}}, "v", ty.Of(s), ast::StorageClass::kStorage, + ast::Access::kReadWrite, + ast::DecorationList{ + create(0), + create(0), + }); + + WrapInFunction(Assign(Source{{56, 78}}, MemberAccessor("v", "a"), + MemberAccessor("v", "a"))); + + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), + "56:78 error: storage type of assignment must be constructible"); } } // namespace diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc index b8fca54db6..be8e45a8b7 100644 --- a/src/resolver/resolver.cc +++ b/src/resolver/resolver.cc @@ -4330,6 +4330,10 @@ bool Resolver::ValidateAssignment(const ast::AssignmentStatement* a) { a->source()); return false; } + if (!storage_type->IsConstructible()) { + AddError("storage type of assignment must be constructible", a->source()); + return false; + } if (lhs_ref->Access() == ast::Access::kRead) { AddError( "cannot store into a read-only type '" + TypeNameOf(a->lhs()) + "'",