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 <noreply+kokoro@google.com>
Auto-Submit: Sarah Mashayekhi <sarahmashay@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc
index b980b96..264b41b 100644
--- a/src/resolver/resolver.cc
+++ b/src/resolver/resolver.cc
@@ -979,8 +979,8 @@
if (info->storage_class != ast::StorageClass::kStorage &&
info->declaration->declared_access() != ast::Access::kUndefined) {
AddError(
- "variables declared not declared in the <storage> storage class must "
- "not declare an access control",
+ "variables not in <storage> 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 2d75c1f..89fa428 100644
--- a/src/resolver/storage_class_validation_test.cc
+++ b/src/resolver/storage_class_validation_test.cc
@@ -99,6 +99,18 @@
R"(56:78 error: variables declared in the <storage> storage class must be of a structure type)");
}
+TEST_F(ResolverStorageClassValidationTest, NotStorage_AccessMode) {
+ // var<private, read> 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> storage class must not declare an access mode)");
+}
+
TEST_F(ResolverStorageClassValidationTest, StorageBufferNoBlockDecoration) {
// struct S { x : i32 };
// var<storage, read> g : S;