OSDN Git Service

compiler: Handle _ with explicit type correctly.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 20 Jan 2012 23:29:10 +0000 (23:29 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 20 Jan 2012 23:29:10 +0000 (23:29 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183358 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/go/gofrontend/parse.cc

index 37a9782..49e42de 100644 (file)
@@ -1883,10 +1883,23 @@ Parse::init_var(const Typed_identifier& tid, Type* type, Expression* init,
     {
       if (!type_from_init && init != NULL)
        {
-         if (!this->gogo_->in_global_scope())
+         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
-           return this->create_dummy_global(type, init, location);
+           {
+             // With both a type and an initializer, 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);
+             static int count;
+             char buf[30];
+             snprintf(buf, sizeof buf, "sink$%d", count);
+             ++count;
+             return this->gogo_->add_variable(buf, var);
+           }
        }
       return this->gogo_->add_sink();
     }