compiler: better error messages for missing interface method

For golang/go#10700

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/273886
This commit is contained in:
Ian Lance Taylor 2020-11-28 12:41:06 -08:00
parent 4f32eced9d
commit 38f1084181
3 changed files with 12 additions and 3 deletions

View file

@ -1,4 +1,4 @@
534fb907c821b052dc430330708d7fa555b91fe3
68b1c7659a6b25d537a4ff3365ab070fa6215b0b
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.

View file

@ -12052,6 +12052,15 @@ Type::bind_field_or_method(Gogo* gogo, const Type* type, Expression* expr,
ambig2.c_str());
else if (found_pointer_method)
go_error_at(location, "method requires a pointer receiver");
else if (it != NULL && it->is_empty())
go_error_at(location,
"reference to method %qs in interface with no methods",
Gogo::message_name(name).c_str());
else if (it == NULL && type->deref()->interface_type() != NULL)
go_error_at(location,
("reference to method %qs in type that is "
"pointer to interface, not interface"),
Gogo::message_name(name).c_str());
else if (nt == NULL && st == NULL && it == NULL)
go_error_at(location,
("reference to field %qs in object which "

View file

@ -1,6 +1,6 @@
// errorcheck
// Copyright 2011 The Go Authors. All rights reserved.
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -12,6 +12,6 @@ func main() {
var x interface{}
switch t := x.(type) {
case 0: // ERROR "type"
t.x = 1 // ERROR "type interface \{\}|reference to undefined field or method"
t.x = 1 // ERROR "type interface \{\}|reference to undefined field or method|interface with no methods"
}
}