compiler: Don't let dot-import names match names from previous files.
The test case for this will be bug488.go in the main repository: https://codereview.appspot.com/118000043 . From-SVN: r212871
This commit is contained in:
parent
aefa5ff4cf
commit
16c6dcc57b
4 changed files with 31 additions and 10 deletions
|
@ -473,7 +473,7 @@ Gogo::import_package(const std::string& filename,
|
|||
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 @@ Gogo::add_sink()
|
|||
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 @@ class Gogo
|
|||
// 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 @@ Import::import_const()
|
|||
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 @@ Import::import_var()
|
|||
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 @@ Import::import_func(Package* package)
|
|||
{
|
||||
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 @@ Gogo::import_unsafe(const std::string& local_name, bool is_local_name_exported,
|
|||
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 @@ Gogo::import_unsafe(const std::string& local_name, bool is_local_name_exported,
|
|||
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 @@ Gogo::import_unsafe(const std::string& local_name, bool is_local_name_exported,
|
|||
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_)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue