compiler: don't permit P.M if P is a pointer type

When lowering method expressions of the form "P.M" where
    P is a pointer type (e.g. "type P *T") make sure we examine
    the method set of P and not T during method lookup.
    
    Fixes golang/go#15722.
    
    Reviewed-on: https://go-review.googlesource.com/24843

From-SVN: r239675
This commit is contained in:
Ian Lance Taylor 2016-08-22 21:30:49 +00:00
parent d79d625275
commit bb748b89df
2 changed files with 5 additions and 3 deletions

View File

@ -1,4 +1,4 @@
affb1bf5fcd7abf05993c54313d8000b93a08d4a 0476944600d456b2616981fff90c77be5e06edd5
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.

View File

@ -11439,7 +11439,8 @@ Expression*
Selector_expression::lower_method_expression(Gogo* gogo) Selector_expression::lower_method_expression(Gogo* gogo)
{ {
Location location = this->location(); Location location = this->location();
Type* type = this->left_->type(); Type* left_type = this->left_->type();
Type* type = left_type;
const std::string& name(this->name_); const std::string& name(this->name_);
bool is_pointer; bool is_pointer;
@ -11469,7 +11470,8 @@ Selector_expression::lower_method_expression(Gogo* gogo)
imethod = it->find_method(name); imethod = it->find_method(name);
} }
if (method == NULL && imethod == NULL) if ((method == NULL && imethod == NULL)
|| (left_type->named_type() != NULL && left_type->points_to() != NULL))
{ {
if (!is_ambiguous) if (!is_ambiguous)
error_at(location, "type %<%s%s%> has no method %<%s%>", error_at(location, "type %<%s%s%> has no method %<%s%>",