diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-08-23 21:04:40 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-08-23 21:04:40 +0000 |
commit | 4500f676e138a5ea3337ebd47745d8b49ba775b5 (patch) | |
tree | ad0d91464e75c09a960cd3be16de2f242062c4d4 /gcc | |
parent | 009e53539dc7e6d0bf5c7084a6c8cae25b4f4c68 (diff) | |
download | gcc-4500f676e138a5ea3337ebd47745d8b49ba775b5.zip gcc-4500f676e138a5ea3337ebd47745d8b49ba775b5.tar.gz gcc-4500f676e138a5ea3337ebd47745d8b49ba775b5.tar.bz2 |
compiler: don't export embedded builtins.
The panic in test/fixedbugs/bug461.go was caused by the fact that
reflect expects unexported fields in a struct to have a valid
package path. If a struct field is an embedded built-in type, it is
now given the package name of the currently compiling package, so it
remains unexported for purposes of reflect.
Fixed Issue 25.
From-SVN: r201951
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/go/gofrontend/types.cc | 27 | ||||
-rw-r--r-- | gcc/go/gofrontend/types.h | 4 |
2 files changed, 28 insertions, 3 deletions
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc index 0a86d47..b32c058 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -4221,6 +4221,22 @@ Struct_field::is_field_name(const std::string& name) const } } +// Return whether this field is an embedded built-in type. + +bool +Struct_field::is_embedded_builtin(Gogo* gogo) const +{ + const std::string& name(this->field_name()); + // We know that a field is an embedded type if it is anonymous. + // We can decide if it is a built-in type by checking to see if it is + // registered globally under the field's name. + // This allows us to distinguish between embedded built-in types and + // embedded types that are aliases to built-in types. + return (this->is_anonymous() + && !Gogo::is_hidden_name(name) + && gogo->lookup_global(name.c_str()) != NULL); +} + // Class Struct_type. // A hash table used to find identical unnamed structs so that they @@ -4835,11 +4851,16 @@ Struct_type::do_type_descriptor(Gogo* gogo, Named_type* name) ++q; go_assert(q->is_field_name("pkgPath")); - if (!Gogo::is_hidden_name(pf->field_name())) - fvals->push_back(Expression::make_nil(bloc)); + bool is_embedded_builtin = pf->is_embedded_builtin(gogo); + if (!Gogo::is_hidden_name(pf->field_name()) && !is_embedded_builtin) + fvals->push_back(Expression::make_nil(bloc)); else { - std::string n = Gogo::hidden_name_pkgpath(pf->field_name()); + std::string n; + if (is_embedded_builtin) + n = gogo->package_name(); + else + n = Gogo::hidden_name_pkgpath(pf->field_name()); Expression* s = Expression::make_string(n, bloc); fvals->push_back(Expression::make_unary(OPERATOR_AND, s, bloc)); } diff --git a/gcc/go/gofrontend/types.h b/gcc/go/gofrontend/types.h index 56626f1..8bc022e 100644 --- a/gcc/go/gofrontend/types.h +++ b/gcc/go/gofrontend/types.h @@ -1926,6 +1926,10 @@ class Struct_field bool is_field_name(const std::string& name) const; + // Return whether this struct field is an embedded built-in type. + bool + is_embedded_builtin(Gogo*) const; + // The field type. Type* type() const |