Go patch committed: Check for identical package name and prefix

Message ID mcrd3ocnt74.fsf@google.com
State New
Headers show

Commit Message

Ian Taylor Jan. 4, 2011, 11:29 p.m.
The use of -fgo-prefix with gccgo can be confusing.  This patch adds an
error message to catch one case where it is required: when you import a
package which uses the same package name and -fgo-prefix option as the
package currently being compiled.  This helps clarify errors messages
which are otherwise confusing.  This addresses issue 1351 in the Go
issue tracker.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.



diff -r 7bf3086196a6 go/gogo.cc
--- a/go/gogo.cc	Tue Jan 04 14:53:28 2011 -0800
+++ b/go/gogo.cc	Tue Jan 04 15:25:53 2011 -0800
@@ -332,6 +332,12 @@ 
   Package* package = imp.import(this, local_name, is_local_name_exported);
   if (package != NULL)
+      if (package->name() == this->package_name()
+	  && package->unique_prefix() == this->unique_prefix())
+	error_at(location,
+		 ("imported package uses same package name and prefix "
+		  "as package being compiled (see -fgo-prefix option)"));
       this->imports_.insert(std::make_pair(filename, package));