From patchwork Fri Sep 21 21:08:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Go patch committed: Better error message Date: Fri, 21 Sep 2012 11:08:19 -0000 From: Ian Taylor X-Patchwork-Id: 185933 Message-Id: To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com This patch to the Go compiler gives a better error message if a method that requires a pointer receiver is invoked with a non-pointer value. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.7 branch. Ian diff -r cb56a10e8798 go/types.cc --- a/go/types.cc Fri Sep 21 10:44:22 2012 -0700 +++ b/go/types.cc Fri Sep 21 14:00:15 2012 -0700 @@ -6845,7 +6845,8 @@ std::string n = Gogo::message_name(p->name()); size_t len = 100 + n.length(); char* buf = new char[len]; - snprintf(buf, len, _("method %s%s%s requires a pointer"), + snprintf(buf, len, + _("method %s%s%s requires a pointer receiver"), open_quote, n.c_str(), close_quote); reason->assign(buf); delete[] buf; @@ -9034,7 +9035,7 @@ Gogo::message_name(name).c_str(), ambig1.c_str(), ambig2.c_str()); else if (found_pointer_method) - error_at(location, "method requires a pointer"); + error_at(location, "method requires a pointer receiver"); else if (nt == NULL && st == NULL && it == NULL) error_at(location, ("reference to field %qs in object which "