]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
compiler: don't permit nil assignment to blank identifier.
authorIan Lance Taylor <ian@gcc.gnu.org>
Wed, 25 Sep 2013 03:28:06 +0000 (03:28 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Wed, 25 Sep 2013 03:28:06 +0000 (03:28 +0000)
Fixes https://code.google.com/p/go/issues/detail?id=6005.

From-SVN: r202881

gcc/go/gofrontend/parse.cc
gcc/go/gofrontend/statements.cc

index 9d112850fee27151f88bc93e956f603892db4f69..befe4bc7d836462e0871aaa6ec110306e74b6fa3 100644 (file)
@@ -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);
index 0261f9d4882b79b1e34cf83abd2f857f4345d569..a5102c0c450546d812b4a5f7bf43aba5eb77199d 100644 (file)
@@ -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;
        }