@@ -14529,38 +14529,48 @@ Selector_expression::lower_method_expression(Gogo* gogo)
14529
14529
is_pointer = true;
14530
14530
type = type->points_to();
14531
14531
}
14532
- Named_type* nt = type->named_type();
14533
- if (nt == NULL)
14534
- {
14535
- go_error_at(location,
14536
- ("method expression requires named type or "
14537
- "pointer to named type"));
14538
- return Expression::make_error(location);
14539
- }
14540
14532
14533
+ Named_type* nt = type->named_type();
14534
+ Struct_type* st = type->struct_type();
14541
14535
bool is_ambiguous;
14542
- Method* method = nt->method_function(name, &is_ambiguous);
14536
+ Method* method = NULL;
14537
+ if (nt != NULL)
14538
+ method = nt->method_function(name, &is_ambiguous);
14539
+ else if (st != NULL)
14540
+ method = st->method_function(name, &is_ambiguous);
14543
14541
const Typed_identifier* imethod = NULL;
14544
14542
if (method == NULL && !is_pointer)
14545
14543
{
14546
- Interface_type* it = nt ->interface_type();
14544
+ Interface_type* it = type ->interface_type();
14547
14545
if (it != NULL)
14548
14546
imethod = it->find_method(name);
14549
14547
}
14550
14548
14551
14549
if ((method == NULL && imethod == NULL)
14552
14550
|| (left_type->named_type() != NULL && left_type->points_to() != NULL))
14553
14551
{
14554
- if (!is_ambiguous)
14555
- go_error_at(location, "type %<%s%s%> has no method %<%s%>",
14556
- is_pointer ? "*" : "",
14557
- nt->message_name().c_str(),
14558
- Gogo::message_name(name).c_str());
14552
+ if (nt != NULL)
14553
+ {
14554
+ if (!is_ambiguous)
14555
+ go_error_at(location, "type %<%s%s%> has no method %<%s%>",
14556
+ is_pointer ? "*" : "",
14557
+ nt->message_name().c_str(),
14558
+ Gogo::message_name(name).c_str());
14559
+ else
14560
+ go_error_at(location, "method %<%s%s%> is ambiguous in type %<%s%>",
14561
+ Gogo::message_name(name).c_str(),
14562
+ is_pointer ? "*" : "",
14563
+ nt->message_name().c_str());
14564
+ }
14559
14565
else
14560
- go_error_at(location, "method %<%s%s%> is ambiguous in type %<%s%>",
14561
- Gogo::message_name(name).c_str(),
14562
- is_pointer ? "*" : "",
14563
- nt->message_name().c_str());
14566
+ {
14567
+ if (!is_ambiguous)
14568
+ go_error_at(location, "type has no method %<%s%>",
14569
+ Gogo::message_name(name).c_str());
14570
+ else
14571
+ go_error_at(location, "method %<%s%> is ambiguous",
14572
+ Gogo::message_name(name).c_str());
14573
+ }
14564
14574
return Expression::make_error(location);
14565
14575
}
14566
14576
@@ -14657,7 +14667,7 @@ Selector_expression::lower_method_expression(Gogo* gogo)
14657
14667
Expression* ve = Expression::make_var_reference(vno, location);
14658
14668
Expression* bm;
14659
14669
if (method != NULL)
14660
- bm = Type::bind_field_or_method(gogo, nt , ve, name, location);
14670
+ bm = Type::bind_field_or_method(gogo, type , ve, name, location);
14661
14671
else
14662
14672
bm = Expression::make_interface_field_reference(ve, name, location);
14663
14673
0 commit comments