Don't crash on redefined variable.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 10 Feb 2011 23:38:50 +0000 (23:38 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 10 Feb 2011 23:38:50 +0000 (23:38 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@170029 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/go/gofrontend/parse.cc

index 53414eb..45ff33d 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