Use foo->source() instead of foo->type()->source() in errors

In these circumstances foo->type() may be null.

BUG=chromium:1238462

Change-Id: I77ed142e3f61f6af52a07e59e290f65613af3514
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/61660
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ryan Harrison 2021-08-11 19:59:44 +00:00 committed by Tint LUCI CQ
parent 36747d7046
commit 3bcbfc7862
1 changed files with 6 additions and 4 deletions

View File

@ -411,7 +411,8 @@ bool Resolver::ValidateAtomic(const ast::Atomic* a, const sem::Atomic* s) {
// https://gpuweb.github.io/gpuweb/wgsl/#atomic-types
// T must be either u32 or i32.
if (!s->Type()->IsAnyOf<sem::U32, sem::I32>()) {
AddError("atomic only supports i32 or u32 types", a->type()->source());
AddError("atomic only supports i32 or u32 types",
a->type() ? a->type()->source() : a->source());
return false;
}
return true;
@ -1043,13 +1044,14 @@ bool Resolver::ValidateAtomicVariable(const VariableInfo* info) {
auto sc = info->storage_class;
auto access = info->access;
auto* type = info->type->UnwrapRef();
auto source = info->declaration->type()->source();
auto source = info->declaration->type() ? info->declaration->type()->source()
: info->declaration->source();
if (type->Is<sem::Atomic>()) {
if (sc != ast::StorageClass::kWorkgroup) {
AddError(
"atomic variables must have <storage> or <workgroup> storage class",
info->declaration->type()->source());
source);
return false;
}
} else if (type->IsAnyOf<sem::Struct, sem::Array>()) {
@ -3382,7 +3384,7 @@ bool Resolver::VariableDeclStatement(const ast::VariableDeclStatement* stmt) {
ast::DisabledValidation::kIgnoreStorageClass)) {
if (!info->type->UnwrapRef()->IsConstructible()) {
AddError("function variable must have a constructible type",
var->type()->source());
var->type() ? var->type()->source() : var->source());
return false;
}
if (info->storage_class != ast::StorageClass::kFunction) {