]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: do not accept (**T).Method expressions.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Sat, 22 Dec 2012 18:13:45 +0000 (19:13 +0100)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Sat, 22 Dec 2012 18:13:45 +0000 (19:13 +0100)
The typechecking code was doing an extra, unnecessary
indirection.

Fixes #4458.

R=golang-dev, daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/6998051

src/cmd/gc/typecheck.c
test/fixedbugs/issue4458.go [new file with mode: 0644]

index 425ee50d171c229b324a0e773ae9c3e1afec07bd..d77dd878cb9d32f10cd26313b025c23f5beb6cb1 100644 (file)
@@ -1781,7 +1781,7 @@ lookdot1(Node *errnode, Sym *s, Type *t, Type *f, int dostrcmp)
 static int
 looktypedot(Node *n, Type *t, int dostrcmp)
 {
-       Type *f1, *f2, *tt;
+       Type *f1, *f2;
        Sym *s;
        
        s = n->right->sym;
@@ -1798,11 +1798,9 @@ looktypedot(Node *n, Type *t, int dostrcmp)
                return 1;
        }
 
-       tt = t;
-       if(t->sym == S && isptr[t->etype])
-               tt = t->type;
-
-       f2 = methtype(tt, 0);
+       // Find the base type: methtype will fail if t
+       // is not of the form T or *T.
+       f2 = methtype(t, 0);
        if(f2 == T)
                return 0;
 
diff --git a/test/fixedbugs/issue4458.go b/test/fixedbugs/issue4458.go
new file mode 100644 (file)
index 0000000..8ee3e87
--- /dev/null
@@ -0,0 +1,20 @@
+// errorcheck
+
+// Copyright 2012 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.
+
+// Issue 4458: gc accepts invalid method expressions
+// like (**T).Method.
+
+package main
+
+type T struct{}
+
+func (T) foo() {}
+
+func main() {
+       av := T{}
+       pav := &av
+       (**T).foo(&pav) // ERROR "no method foo"
+}