1
0
mirror of https://github.com/golang/go synced 2024-11-25 12:07:56 -07:00

gc: check parameter declarations in interface fields

Fixes #1663.
Fixes #1871.

R=rsc, lstoakes
CC=golang-dev
https://golang.org/cl/4530084
This commit is contained in:
Anthony Martin 2011-05-31 13:41:32 -04:00 committed by Russ Cox
parent de15f6165e
commit 67b4db9e9e
4 changed files with 50 additions and 0 deletions

View File

@ -523,6 +523,30 @@ colas(NodeList *left, NodeList *right)
return as; 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 * declare the function proper
* and declare the arguments. * and declare the arguments.

View File

@ -870,6 +870,7 @@ void funcbody(Node *n);
void funccompile(Node *n, int isclosure); void funccompile(Node *n, int isclosure);
void funchdr(Node *n); void funchdr(Node *n);
Type* functype(Node *this, NodeList *in, NodeList *out); Type* functype(Node *this, NodeList *in, NodeList *out);
void ifacedcl(Node *n);
int isifacemethod(Type *f); int isifacemethod(Type *f);
void markdcl(void); void markdcl(void);
Node* methodname(Node *n, Type *t); Node* methodname(Node *n, Type *t);

View File

@ -1380,6 +1380,7 @@ interfacedcl:
new_name indcl new_name indcl
{ {
$$ = nod(ODCLFIELD, $1, $2); $$ = nod(ODCLFIELD, $1, $2);
ifacedcl($$);
} }
| packname | packname
{ {

24
test/fixedbugs/bug342.go Normal file
View File

@ -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
*/