Patchwork go patch committed: Don't crash on redefined variable

login
register
mail settings
Submitter Ian Taylor
Date Feb. 10, 2011, 11:38 p.m.
Message ID <mcr4o8biho3.fsf@google.com>
Download mbox | patch
Permalink /patch/82693/
State New
Headers show

Comments

Ian Taylor - Feb. 10, 2011, 11:38 p.m.
This patch to the Go frontend avoids crashing if a variable name
erroneously redefines some name that already exists but is not a
variable.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 2ad66018000c go/parse.cc
--- a/go/parse.cc	Thu Feb 10 15:06:29 2011 -0800
+++ b/go/parse.cc	Thu Feb 10 15:33:40 2011 -0800
@@ -1848,7 +1848,13 @@ 
   *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