diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-08 23:27:33 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-08 23:27:33 +0000 |
commit | 1fbbc69cdffb4715ba395e7754d801aebdf992f7 (patch) | |
tree | 2de9d0efcb376d34885e8e97b873e5013b7bb9c6 /gcc/go | |
parent | 0ee1c847f75174bb87a54edb32f7f7cf27681300 (diff) | |
download | gcc-1fbbc69cdffb4715ba395e7754d801aebdf992f7.zip gcc-1fbbc69cdffb4715ba395e7754d801aebdf992f7.tar.gz gcc-1fbbc69cdffb4715ba395e7754d801aebdf992f7.tar.bz2 |
compiler: Don't check for hidden fields on struct assignments.
From-SVN: r182143
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 37 | ||||
-rw-r--r-- | gcc/go/gofrontend/types.cc | 2 |
2 files changed, 37 insertions, 2 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index a80c823..7314288 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -12817,7 +12817,22 @@ Composite_literal_expression::lower_struct(Gogo* gogo, Type* type) Location location = this->location(); Struct_type* st = type->struct_type(); if (this->vals_ == NULL || !this->has_keys_) - return new Struct_construction_expression(type, this->vals_, location); + { + if (this->vals_ != NULL && !this->vals_->empty()) + { + std::string reason; + if (type->has_hidden_fields(NULL, &reason)) + { + if (reason.empty()) + error_at(this->location(), + "implicit assignment of hidden field"); + else + error_at(this->location(), "%s", reason.c_str()); + } + } + + return new Struct_construction_expression(type, this->vals_, location); + } size_t field_count = st->field_count(); std::vector<Expression*> vals(field_count); @@ -12964,6 +12979,26 @@ Composite_literal_expression::lower_struct(Gogo* gogo, Type* type) return Expression::make_error(location); } + if (type->named_type() != NULL + && type->named_type()->named_object()->package() != NULL + && Gogo::is_hidden_name(sf->field_name())) + error_at(name_expr->location(), + "assignment of unexported field %qs in %qs literal", + Gogo::message_name(sf->field_name()).c_str(), + type->named_type()->message_name().c_str()); + else + { + std::string reason; + if (sf->type()->has_hidden_fields(NULL, &reason)) + { + if (reason.empty()) + error_at(name_expr->location(), + "implicit assignment of hidden field"); + else + error_at(name_expr->location(), "%s", reason.c_str()); + } + } + vals[index] = val; } diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc index f63d169..fed83b3 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -605,7 +605,7 @@ Type::are_assignable_check_hidden(const Type* lhs, const Type* rhs, bool Type::are_assignable(const Type* lhs, const Type* rhs, std::string* reason) { - return Type::are_assignable_check_hidden(lhs, rhs, true, reason); + return Type::are_assignable_check_hidden(lhs, rhs, false, reason); } // Like are_assignable but don't check for hidden fields. |