diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-09-25 03:28:06 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-09-25 03:28:06 +0000 |
commit | 28d18db363050e2e8122d202cd59d131a3ffa167 (patch) | |
tree | 6cadfca1790ee7591d7dc8676991f00011e27f1f /gcc | |
parent | 6a9502fdf909ec3fbda5f42b6963f726c8cab4ed (diff) | |
download | gcc-28d18db363050e2e8122d202cd59d131a3ffa167.zip gcc-28d18db363050e2e8122d202cd59d131a3ffa167.tar.gz gcc-28d18db363050e2e8122d202cd59d131a3ffa167.tar.bz2 |
compiler: don't permit nil assignment to blank identifier.
Fixes https://code.google.com/p/go/issues/detail?id=6005.
From-SVN: r202881
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/go/gofrontend/parse.cc | 5 | ||||
-rw-r--r-- | gcc/go/gofrontend/statements.cc | 14 |
2 files changed, 14 insertions, 5 deletions
diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index 9d11285..befe4bc 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -1940,12 +1940,9 @@ Parse::init_var(const Typed_identifier& tid, Type* type, Expression* init, { if (this->gogo_->in_global_scope()) return this->create_dummy_global(type, init, location); - else if (type == NULL) - this->gogo_->add_statement(Statement::make_statement(init, true)); else { - // With both a type and an initializer, create a dummy - // variable so that we will check whether the + // Create a dummy variable so that we will check whether the // initializer can be assigned to the type. Variable* var = new Variable(type, init, false, false, false, location); diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc index 0261f9d..a5102c0 100644 --- a/gcc/go/gofrontend/statements.cc +++ b/gcc/go/gofrontend/statements.cc @@ -594,6 +594,15 @@ Assignment_statement::do_check_types(Gogo*) Type* lhs_type = this->lhs_->type(); Type* rhs_type = this->rhs_->type(); + + // Invalid assignment of nil to the blank identifier. + if (lhs_type->is_sink_type() + && rhs_type->is_nil_type()) + { + this->report_error(_("use of untyped nil")); + return; + } + std::string reason; bool ok; if (this->are_hidden_fields_ok_) @@ -975,7 +984,10 @@ Tuple_assignment_statement::do_lower(Gogo*, Named_object*, Block* enclosing, if ((*plhs)->is_sink_expression()) { - b->add_statement(Statement::make_statement(*prhs, true)); + if ((*prhs)->type()->is_nil_type()) + this->report_error(_("use of untyped nil")); + else + b->add_statement(Statement::make_statement(*prhs, true)); continue; } |