diff --git a/src/resolver/resolver_validation.cc b/src/resolver/resolver_validation.cc index a457ec3304..5a375aa4d5 100644 --- a/src/resolver/resolver_validation.cc +++ b/src/resolver/resolver_validation.cc @@ -493,6 +493,14 @@ bool Resolver::ValidateGlobalVariable(const sem::Variable* var) { } } + if (var->StorageClass() == ast::StorageClass::kFunction) { + AddError( + "variables declared at module scope must not be in the function " + "storage class", + decl->source); + return false; + } + auto binding_point = decl->BindingPoint(); switch (var->StorageClass()) { case ast::StorageClass::kUniform: diff --git a/src/resolver/storage_class_validation_test.cc b/src/resolver/storage_class_validation_test.cc index 9391edcca9..4c6799fcd6 100644 --- a/src/resolver/storage_class_validation_test.cc +++ b/src/resolver/storage_class_validation_test.cc @@ -34,6 +34,17 @@ TEST_F(ResolverStorageClassValidationTest, GlobalVariableNoStorageClass_Fail) { "12:34 error: global variables must have a storage class"); } +TEST_F(ResolverStorageClassValidationTest, + GlobalVariableFunctionStorageClass_Fail) { + // var g : f32; + Global(Source{{12, 34}}, "g", ty.f32(), ast::StorageClass::kFunction); + + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), + "12:34 error: variables declared at module scope must not be in " + "the function storage class"); +} + TEST_F(ResolverStorageClassValidationTest, StorageBufferBool) { // var g : i32; Global(Source{{56, 78}}, "g", ty.i32(), ast::StorageClass::kStorage,