Don't crash on redefined variable.
authorIan Lance Taylor <ian@gcc.gnu.org>
Thu, 10 Feb 2011 23:38:50 +0000 (23:38 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Thu, 10 Feb 2011 23:38:50 +0000 (23:38 +0000)
From-SVN: r170029

gcc/go/gofrontend/parse.cc

index 53414ebcb09cabda6f6874f1d22201771314cab4..45ff33df3d8406bba9246beacddd5c34dc1bdd7f 100644 (file)
@@ -1848,7 +1848,13 @@ Parse::init_var(const Typed_identifier& tid, Type* type, Expression* init,
   *is_new = true;
   Variable* var = new Variable(type, init, this->gogo_->in_global_scope(),
                               false, false, location);
-  return this->gogo_->add_variable(tid.name(), var);
+  Named_object* no = this->gogo_->add_variable(tid.name(), var);
+  if (!no->is_variable())
+    {
+      // The name is already defined, so we just gave an error.
+      return this->gogo_->add_sink();
+    }
+  return no;
 }
 
 // Create a dummy global variable to force an initializer to be run in