From 085dcbbe20377ab559e10d61cf48c53f3f12c56d Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 28 Jul 2021 09:59:35 +0000 Subject: [PATCH] validation: redundant access mode, fix error msg and add unittest Bug: tint:1070 Change-Id: Ibc6fb02abf891f57874494ddb8dcac0b4480f990 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/60140 Kokoro: Kokoro Auto-Submit: Sarah Mashayekhi Commit-Queue: Ben Clayton Reviewed-by: Ben Clayton --- src/resolver/resolver.cc | 4 ++-- src/resolver/storage_class_validation_test.cc | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc index b980b965e3..264b41be1c 100644 --- a/src/resolver/resolver.cc +++ b/src/resolver/resolver.cc @@ -979,8 +979,8 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) { if (info->storage_class != ast::StorageClass::kStorage && info->declaration->declared_access() != ast::Access::kUndefined) { AddError( - "variables declared not declared in the storage class must " - "not declare an access control", + "variables not in storage class must not declare an access " + "mode", info->declaration->source()); return false; } diff --git a/src/resolver/storage_class_validation_test.cc b/src/resolver/storage_class_validation_test.cc index 2d75c1f581..89fa428cb8 100644 --- a/src/resolver/storage_class_validation_test.cc +++ b/src/resolver/storage_class_validation_test.cc @@ -99,6 +99,18 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferBoolAlias) { R"(56:78 error: variables declared in the storage class must be of a structure type)"); } +TEST_F(ResolverStorageClassValidationTest, NotStorage_AccessMode) { + // var g : a; + Global(Source{{56, 78}}, "g", ty.i32(), ast::StorageClass::kPrivate, + ast::Access::kRead); + + ASSERT_FALSE(r()->Resolve()); + + EXPECT_EQ( + r()->error(), + R"(56:78 error: variables not in storage class must not declare an access mode)"); +} + TEST_F(ResolverStorageClassValidationTest, StorageBufferNoBlockDecoration) { // struct S { x : i32 }; // var g : S;