public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@golang.org>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
	 gofrontend-dev <gofrontend-dev@googlegroups.com>
Subject: Go patch committed: Better error message for unknown package name
Date: Tue, 5 Jul 2022 17:08:20 -0700	[thread overview]
Message-ID: <CAOyqgcVOGTNRQxiRcK5Twk-RJ4W6pZvBf22zEA-6Nr=WZjTrsQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 310 bytes --]

This patch to the Go frontend gives a  better error message for an
unknown package name, saying "undefined reference" rather than
"expected package".  This requires updating a test.  This fixes
https://go.dev/issue/51237.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2042 bytes --]

db1256cfb4620c4d52175002940347d399148502
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 7b1d3011fff..461e2fdf271 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6479d5976c5d848ec6f5843041275723a00006b0
+a209dca9ec918535977dcab99fd9bb60986ffacd
 
 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/parse.cc b/gcc/go/gofrontend/parse.cc
index a3c6f630a09..c93d82bba39 100644
--- a/gcc/go/gofrontend/parse.cc
+++ b/gcc/go/gofrontend/parse.cc
@@ -191,7 +191,11 @@ Parse::qualified_ident(std::string* pname, Named_object** ppackage)
   Named_object* package = this->gogo_->lookup(name, NULL);
   if (package == NULL || !package->is_package())
     {
-      go_error_at(this->location(), "expected package");
+      if (package == NULL)
+	go_error_at(this->location(), "reference to undefined name %qs",
+		    Gogo::message_name(name).c_str());
+      else
+	go_error_at(this->location(), "expected package");
       // We expect . IDENTIFIER; skip both.
       if (this->advance_token()->is_identifier())
 	this->advance_token();
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue27938.go b/gcc/testsuite/go.test/test/fixedbugs/issue27938.go
index ed974e642df..aecc67678ac 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue27938.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue27938.go
@@ -11,13 +11,13 @@
 package p
 
 type _ struct {
-	F sync.Mutex // ERROR "undefined: sync|expected package"
+	F sync.Mutex // ERROR "undefined: sync|expected package|reference to undefined name"
 }
 
 type _ struct {
-	sync.Mutex // ERROR "undefined: sync|expected package"
+	sync.Mutex // ERROR "undefined: sync|expected package|reference to undefined name"
 }
 
 type _ interface {
-	sync.Mutex // ERROR "undefined: sync|expected package|expected signature or type name"
+	sync.Mutex // ERROR "undefined: sync|expected package|expected signature or type name|reference to undefined name"
 }

                 reply	other threads:[~2022-07-06  0:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOyqgcVOGTNRQxiRcK5Twk-RJ4W6pZvBf22zEA-6Nr=WZjTrsQ@mail.gmail.com' \
    --to=iant@golang.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gofrontend-dev@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).