diff mbox

Go patch committed: Disallow call of *T method using **T variable

Message ID mcrr4021sfu.fsf@iant-glaptop.roam.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor Aug. 27, 2014, 4:12 a.m. UTC
This patch by Chris Manghane fixes the Go frontend to not permit calling
a pointer method on *T with a variable of **T.  Previously it was
incorrectly dereferencing the **T to get a *T and using that to call the
method.  Fixing this required tweaking one test case.  Bootstrapped and
ran Go testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.
This fixes issue 8583 in the Go project.

Ian
diff mbox

Patch

Index: gcc/go/gofrontend/types.cc
===================================================================
--- gcc/go/gofrontend/types.cc	(revision 213928)
+++ gcc/go/gofrontend/types.cc	(working copy)
@@ -9453,10 +9453,11 @@  Type::bind_field_or_method(Gogo* gogo, c
 	  else
 	    go_unreachable();
 	  go_assert(m != NULL);
-	  if (dereferenced && m->is_value_method())
+	  if (dereferenced)
 	    {
 	      error_at(location,
-		       "calling value method requires explicit dereference");
+		       "calling method %qs requires explicit dereference",
+		       Gogo::message_name(name).c_str());
 	      return Expression::make_error(location);
 	    }
 	  if (!m->is_value_method() && expr->type()->points_to() == NULL)
Index: gcc/testsuite/go.test/test/fixedbugs/bug371.go
===================================================================
--- gcc/testsuite/go.test/test/fixedbugs/bug371.go	(revision 213928)
+++ gcc/testsuite/go.test/test/fixedbugs/bug371.go	(working copy)
@@ -8,10 +8,10 @@ 
 
 package main
 
-type T struct {}
+type T struct{}
 
 func (t *T) pm() {}
-func (t T) m() {}
+func (t T) m()   {}
 
 func main() {
 	p := &T{}
@@ -20,5 +20,5 @@  func main() {
 
 	q := &p
 	q.m()  // ERROR "requires explicit dereference"
-	q.pm()
+	q.pm() // ERROR "requires explicit dereference"
 }