Resolver: Clean up diagnostics

Don't have a separate diagnostic list, just put the errors straight into the ProgramBuilder's diagnostics.
This also fixes an issue where we were taking the stringified diagnostic list and creating a single error on resolution failure. This was the cause of the `error: error:` messages sometimes seen.

Also fix a stupid negated-logic bug around the "resolving failed, but no error was raised" ICE.

Change-Id: Iddf1f61e4be21137731dfc204210562abbf612b0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49963
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/program.cc b/src/program.cc
index 9029bb5..dff5616 100644
--- a/src/program.cc
+++ b/src/program.cc
@@ -45,7 +45,6 @@
   if (builder.ResolveOnBuild() && builder.IsValid()) {
     resolver::Resolver resolver(&builder);
     if (!resolver.Resolve()) {
-      diagnostics_.add_error(resolver.error());
       is_valid_ = false;
     }
   }
diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc
index 9779c40..b46e4fe 100644
--- a/src/resolver/resolver.cc
+++ b/src/resolver/resolver.cc
@@ -124,7 +124,9 @@
 }  // namespace
 
 Resolver::Resolver(ProgramBuilder* builder)
-    : builder_(builder), intrinsic_table_(IntrinsicTable::Create()) {}
+    : builder_(builder),
+      diagnostics_(builder->Diagnostics()),
+      intrinsic_table_(IntrinsicTable::Create()) {}
 
 Resolver::~Resolver() = default;
 
@@ -158,7 +160,7 @@
 
   bool result = ResolveInternal();
 
-  if (result && diagnostics_.contains_errors()) {
+  if (!result && !diagnostics_.contains_errors()) {
     TINT_ICE(diagnostics_) << "resolving failed, but no error was raised";
     return false;
   }
diff --git a/src/resolver/resolver.h b/src/resolver/resolver.h
index 1780cb8..4426138 100644
--- a/src/resolver/resolver.h
+++ b/src/resolver/resolver.h
@@ -360,8 +360,8 @@
   void Mark(const ast::Node* node);
 
   ProgramBuilder* const builder_;
+  diag::List& diagnostics_;
   std::unique_ptr<IntrinsicTable> const intrinsic_table_;
-  diag::List diagnostics_;
   BlockInfo* current_block_ = nullptr;
   ScopeStack<VariableInfo*> variable_stack_;
   std::unordered_map<Symbol, FunctionInfo*> symbol_to_function_;