This patch to the Go frontend generates better error messages for a
missing interface method.  This is for https://golang.org/issue/10700.
This requires updating one test to the one in the source repo.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
38f10841817a9fee28ee97c7115b6f4d24f5245d
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index c14a10f1265..af4d0526b2f 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -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.
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index 286ecc16366..23d1647c1fa 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -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 "
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug340.go 
b/gcc/testsuite/go.test/test/fixedbugs/bug340.go
index d996ab64cd4..8c543c98d97 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/bug340.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/bug340.go
@@ -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"
        }
 }

Reply via email to