From d5f3d14a4282516308125595fcc79d1b6d235f9c Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 10 Feb 2011 23:38:50 +0000 Subject: Don't crash on redefined variable. From-SVN: r170029 --- gcc/go/gofrontend/parse.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'gcc') diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index 53414eb..45ff33d 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -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 -- cgit v1.1