resolver: Fix ICE when using a builtin as a type

Bug: chromium:1308209
Change-Id: I779d7fcb4a32640663077cb2176875f6081098a0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/84260
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2022-03-22 14:04:41 +00:00 committed by Tint LUCI CQ
parent 7d38b88d77
commit e07c40af14
2 changed files with 16 additions and 0 deletions

View File

@ -275,6 +275,14 @@ sem::Type* Resolver::Type(const ast::Type* ty) {
return nullptr;
},
[&](Default) {
if (auto* tn = ty->As<ast::TypeName>()) {
if (IsBuiltin(tn->name)) {
auto name = builder_->Symbols().NameFor(tn->name);
AddError("cannot use builtin '" + name + "' as type",
ty->source);
return nullptr;
}
}
TINT_UNREACHABLE(Resolver, diagnostics_)
<< "Unhandled resolved type '"
<< (resolved ? resolved->TypeInfo().name : "<null>")

View File

@ -705,6 +705,14 @@ TEST_F(ResolverTypeValidationTest, FunctionAsType) {
note: 'f' declared here)");
}
TEST_F(ResolverTypeValidationTest, BuiltinAsType) {
// var<private> v : max;
Global("v", ty.type_name("max"), ast::StorageClass::kPrivate);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "error: cannot use builtin 'max' as type");
}
namespace GetCanonicalTests {
struct Params {
builder::ast_type_func_ptr create_ast_type;