]> Cypherpunks repositories - gostls13.git/commitdiff
gc: check parameter declarations in interface fields
authorAnthony Martin <ality@pbrane.org>
Tue, 31 May 2011 17:41:32 +0000 (13:41 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 31 May 2011 17:41:32 +0000 (13:41 -0400)
Fixes #1663.
Fixes #1871.

R=rsc, lstoakes
CC=golang-dev
https://golang.org/cl/4530084

src/cmd/gc/dcl.c
src/cmd/gc/go.h
src/cmd/gc/go.y
test/fixedbugs/bug342.go [new file with mode: 0644]

index 99af18d9f11d5c2b336a523a74989b43efa06aa7..dfdd11caeb9f5b6dacfe57958fbdeb0835aeb9dd 100644 (file)
@@ -523,6 +523,30 @@ colas(NodeList *left, NodeList *right)
        return as;
 }
 
+/*
+ * declare the arguments in an
+ * interface field declaration.
+ */
+void
+ifacedcl(Node *n)
+{
+       if(n->op != ODCLFIELD || n->right == N)
+               fatal("ifacedcl");
+
+       dclcontext = PAUTO;
+       markdcl();
+       funcdepth++;
+       n->outer = curfn;
+       curfn = n;
+       funcargs(n->right);
+
+       // funcbody is normally called after the parser has
+       // seen the body of a function but since an interface
+       // field declaration does not have a body, we must
+       // call it now to pop the current declaration context.
+       funcbody(n);
+}
+
 /*
  * declare the function proper
  * and declare the arguments.
index 359881e11ea0f99bf9c05ba42e072c48f18f51e9..3f07befcbd47cd1121edd551120e7e1d297935a2 100644 (file)
@@ -870,6 +870,7 @@ void        funcbody(Node *n);
 void   funccompile(Node *n, int isclosure);
 void   funchdr(Node *n);
 Type*  functype(Node *this, NodeList *in, NodeList *out);
+void   ifacedcl(Node *n);
 int    isifacemethod(Type *f);
 void   markdcl(void);
 Node*  methodname(Node *n, Type *t);
index 7adfd002a3e01763064134962a4d3c72dfa13ec5..fdaab4fa4671c74a0d2d45e8c8874b57eb05c339 100644 (file)
@@ -1380,6 +1380,7 @@ interfacedcl:
        new_name indcl
        {
                $$ = nod(ODCLFIELD, $1, $2);
+               ifacedcl($$);
        }
 |      packname
        {
diff --git a/test/fixedbugs/bug342.go b/test/fixedbugs/bug342.go
new file mode 100644 (file)
index 0000000..0852cdd
--- /dev/null
@@ -0,0 +1,24 @@
+// 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.
+
+// Issue 1871.
+
+package p
+
+type a interface {
+       foo(x int) (x int) // ERROR "redeclared|redefinition"
+}
+
+var b interface {
+       bar(y int) (y int) // ERROR "redeclared|redefinition"
+}
+
+/*
+Previously:
+
+bug.go:1 x redclared in this block
+    previous declaration at bug.go:1
+*/