]> Cypherpunks repositories - gostls13.git/commitdiff
gc: correct receiver in method missing error
authorLorenzo Stoakes <lstoakes@gmail.com>
Fri, 11 Feb 2011 22:47:58 +0000 (17:47 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 11 Feb 2011 22:47:58 +0000 (17:47 -0500)
Fixes #1324.

R=rsc1, r, rsc
CC=golang-dev
https://golang.org/cl/3435042

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

index 931d0327a4e88c61179c1dd789c95f5f29c70f52..5edca964aa1014cd827f135d085c1d8a209e94af 100644 (file)
@@ -96,7 +96,7 @@ typecheck(Node **np, int top)
        Node *n, *l, *r;
        NodeList *args;
        int lno, ok, ntop;
-       Type *t, *missing, *have;
+       Type *t, *tp, *missing, *have;
        Sym *sym;
        Val v;
        char *why;
@@ -552,6 +552,7 @@ reswitch:
                        ok = Erv;
                        goto ret;
                }
+               tp = t;
                if(isptr[t->etype] && t->type->etype != TINTER) {
                        t = t->type;
                        if(t == T)
@@ -563,7 +564,7 @@ reswitch:
                        if(lookdot(n, t, 1))
                                yyerror("%#N undefined (cannot refer to unexported field or method %S)", n, n->right->sym);
                        else
-                               yyerror("%#N undefined (type %T has no field or method %S)", n, t, n->right->sym);
+                               yyerror("%#N undefined (type %T has no field or method %S)", n, tp, n->right->sym);
                        goto error;
                }
                switch(n->op) {
diff --git a/test/fixedbugs/bug322.go b/test/fixedbugs/bug322.go
new file mode 100644 (file)
index 0000000..bfb5283
--- /dev/null
@@ -0,0 +1,20 @@
+// errchk $G $D/$F.go
+
+// Copyright 2011 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.
+
+package main
+
+type T struct{}
+type P *T
+
+func (t *T) Meth() {}
+func (t T) Meth2() {}
+
+func main() {
+       t := &T{}
+       p := P(t)
+       p.Meth()  // ERROR "undefined \(type P"
+       p.Meth2() // ERROR "undefined \(type P"
+}
\ No newline at end of file