@@ -473,7 +473,7 @@
bindings->begin_declarations();
p != bindings->end_declarations();
++p)
- this->add_named_object(p->second);
+ this->add_dot_import_object(p->second);
}
else if (ln == "_")
package->set_uses_sink_alias();
@@ -1968,11 +1968,32 @@
return Named_object::make_sink();
}
-// Add a named object.
+// Add a named object for a dot import.
void
-Gogo::add_named_object(Named_object* no)
-{
+Gogo::add_dot_import_object(Named_object* no)
+{
+ // If the name already exists, then it was defined in some file seen
+ // earlier. If the earlier name is just a declaration, don't add
+ // this name, because that will cause the previous declaration to
+ // merge to this imported name, which should not happen. Just add
+ // this name to the list of file block names to get appropriate
+ // errors if we see a later definition.
+ Named_object* e = this->package_->bindings()->lookup(no->name());
+ if (e != NULL && e->package() == NULL)
+ {
+ if (e->is_unknown())
+ e = e->resolve();
+ if (e->package() == NULL
+ && (e->is_type_declaration()
+ || e->is_function_declaration()
+ || e->is_unknown()))
+ {
+ this->add_file_block_name(no->name(), no->location());
+ return;
+ }
+ }
+
this->current_bindings()->add_named_object(no);
}
@@ -397,7 +397,7 @@
// Add a named object to the current namespace. This is used for
// import . "package".
void
- add_named_object(Named_object*);
+ add_dot_import_object(Named_object*);
// Add an identifier to the list of names seen in the file block.
void
@@ -431,7 +431,7 @@
Typed_identifier tid(name, type, this->location_);
Named_object* no = this->package_->add_constant(tid, expr);
if (this->add_to_globals_)
- this->gogo_->add_named_object(no);
+ this->gogo_->add_dot_import_object(no);
}
// Import a type.
@@ -464,7 +464,7 @@
Named_object* no;
no = this->package_->add_variable(name, var);
if (this->add_to_globals_)
- this->gogo_->add_named_object(no);
+ this->gogo_->add_dot_import_object(no);
}
// Import a function into PACKAGE. PACKAGE is normally
@@ -518,7 +518,7 @@
{
no = package->add_function_declaration(name, fntype, loc);
if (this->add_to_globals_)
- this->gogo_->add_named_object(no);
+ this->gogo_->add_dot_import_object(no);
}
return no;
}
@@ -66,7 +66,7 @@
fntype->set_is_builtin();
no = bindings->add_function_declaration("Sizeof", package, fntype, bloc);
if (add_to_globals)
- this->add_named_object(no);
+ this->add_dot_import_object(no);
// Offsetof.
results = new Typed_identifier_list;
@@ -76,7 +76,7 @@
fntype->set_is_builtin();
no = bindings->add_function_declaration("Offsetof", package, fntype, bloc);
if (add_to_globals)
- this->add_named_object(no);
+ this->add_dot_import_object(no);
// Alignof.
results = new Typed_identifier_list;
@@ -86,7 +86,7 @@
fntype->set_is_builtin();
no = bindings->add_function_declaration("Alignof", package, fntype, bloc);
if (add_to_globals)
- this->add_named_object(no);
+ this->add_dot_import_object(no);
if (!this->imported_unsafe_)
{