mirror of
https://github.com/golang/go
synced 2024-09-25 09:20:18 -06:00
permit only one method name per method signature in interface types
(in sync with spec CL 35047) R=rsc DELTA=44 (4 added, 8 deleted, 32 changed) OCL=35048 CL=35054
This commit is contained in:
parent
320406d155
commit
ec10bf8f43
@ -305,16 +305,13 @@ func (p *parser) parseIdent() *ast.Ident {
|
||||
}
|
||||
|
||||
|
||||
func (p *parser) parseIdentList(x ast.Expr) []*ast.Ident {
|
||||
func (p *parser) parseIdentList() []*ast.Ident {
|
||||
if p.trace {
|
||||
defer un(trace(p, "IdentList"));
|
||||
}
|
||||
|
||||
list := vector.New(0);
|
||||
if x == nil {
|
||||
x = p.parseIdent();
|
||||
}
|
||||
list.Push(x);
|
||||
list.Push(p.parseIdent());
|
||||
for p.tok == token.COMMA {
|
||||
p.next();
|
||||
list.Push(p.parseIdent());
|
||||
@ -587,7 +584,7 @@ func (p *parser) parseParameterList(ellipsisOk bool) []*ast.Field {
|
||||
|
||||
for p.tok == token.COMMA {
|
||||
p.next();
|
||||
idents := p.parseIdentList(nil);
|
||||
idents := p.parseIdentList();
|
||||
typ := p.parseParameterType(ellipsisOk);
|
||||
list.Push(&ast.Field{nil, idents, typ, nil, nil});
|
||||
}
|
||||
@ -679,9 +676,9 @@ func (p *parser) parseMethodSpec() *ast.Field {
|
||||
var idents []*ast.Ident;
|
||||
var typ ast.Expr;
|
||||
x := p.parseQualifiedIdent();
|
||||
if _, isIdent := x.(*ast.Ident); isIdent && (p.tok == token.COMMA || p.tok == token.LPAREN) {
|
||||
// methods
|
||||
idents = p.parseIdentList(x);
|
||||
if ident, isIdent := x.(*ast.Ident); isIdent && p.tok == token.LPAREN {
|
||||
// method
|
||||
idents = []*ast.Ident{ident};
|
||||
params, results := p.parseSignature();
|
||||
typ = &ast.FuncType{noPos, params, results};
|
||||
} else {
|
||||
@ -1748,7 +1745,7 @@ func parseConstSpec(p *parser, doc *ast.CommentGroup, getSemi bool) (spec ast.Sp
|
||||
defer un(trace(p, "ConstSpec"));
|
||||
}
|
||||
|
||||
idents := p.parseIdentList(nil);
|
||||
idents := p.parseIdentList();
|
||||
typ := p.tryType();
|
||||
var values []ast.Expr;
|
||||
if typ != nil || p.tok == token.ASSIGN {
|
||||
@ -1779,7 +1776,7 @@ func parseVarSpec(p *parser, doc *ast.CommentGroup, getSemi bool) (spec ast.Spec
|
||||
defer un(trace(p, "VarSpec"));
|
||||
}
|
||||
|
||||
idents := p.parseIdentList(nil);
|
||||
idents := p.parseIdentList();
|
||||
typ := p.tryType();
|
||||
var values []ast.Expr;
|
||||
if typ == nil || p.tok == token.ASSIGN {
|
||||
|
@ -610,12 +610,9 @@ func (p *printer) fieldList(lbrace token.Position, list []*ast.Field, rbrace tok
|
||||
} else { // interface
|
||||
for i, f := range list {
|
||||
p.leadComment(f.Doc);
|
||||
p.identList(f.Names);
|
||||
if len(f.Names) > 1 {
|
||||
p.print(blank);
|
||||
}
|
||||
if ftyp, isFtyp := f.Type.(*ast.FuncType); isFtyp {
|
||||
// method(s)
|
||||
// method
|
||||
p.expr(f.Names[0]); // exactly one name
|
||||
p.signature(ftyp.Params, ftyp.Results);
|
||||
} else {
|
||||
// embedded interface
|
||||
|
9
src/pkg/go/printer/testdata/comments.go
vendored
9
src/pkg/go/printer/testdata/comments.go
vendored
@ -42,20 +42,21 @@ type SZ interface {}
|
||||
|
||||
// The I0 interface; no method is exported.
|
||||
type I0 interface {
|
||||
f, g (x int) int; // 2 unexported methods
|
||||
f(x int) int; // unexported method
|
||||
}
|
||||
|
||||
// The I1 interface; some methods are not exported.
|
||||
type I1 interface {
|
||||
I0;
|
||||
F, G (x float) float; // 2 exported methods
|
||||
H, g (x int) int; // 1 unexported method
|
||||
F(x float) float; // exported methods
|
||||
g(x int) int; // unexported method
|
||||
}
|
||||
|
||||
// The I2 interface; all methods are exported.
|
||||
type I1 interface {
|
||||
I0;
|
||||
F, G (x float) float; // 2 exported methods
|
||||
F(x float) float; // exported method
|
||||
G(x float) float; // exported method
|
||||
}
|
||||
|
||||
// This comment group should be separated
|
||||
|
9
src/pkg/go/printer/testdata/comments.golden
vendored
9
src/pkg/go/printer/testdata/comments.golden
vendored
@ -42,20 +42,21 @@ type SZ interface{}
|
||||
|
||||
// The I0 interface; no method is exported.
|
||||
type I0 interface {
|
||||
f, g (x int) int; // 2 unexported methods
|
||||
f(x int) int; // unexported method
|
||||
}
|
||||
|
||||
// The I1 interface; some methods are not exported.
|
||||
type I1 interface {
|
||||
I0;
|
||||
F, G (x float) float; // 2 exported methods
|
||||
H, g (x int) int; // 1 unexported method
|
||||
F(x float) float; // exported methods
|
||||
g(x int) int; // unexported method
|
||||
}
|
||||
|
||||
// The I2 interface; all methods are exported.
|
||||
type I1 interface {
|
||||
I0;
|
||||
F, G (x float) float; // 2 exported methods
|
||||
F(x float) float; // exported method
|
||||
G(x float) float; // exported method
|
||||
}
|
||||
|
||||
// This comment group should be separated
|
||||
|
6
src/pkg/go/printer/testdata/comments.x
vendored
6
src/pkg/go/printer/testdata/comments.x
vendored
@ -35,13 +35,13 @@ type I0 interface {
|
||||
// The I1 interface; some methods are not exported.
|
||||
type I1 interface {
|
||||
I0;
|
||||
F, G (x float) float;
|
||||
H(x int) int;
|
||||
F(x float) float;
|
||||
// contains unexported methods
|
||||
}
|
||||
|
||||
// The I2 interface; all methods are exported.
|
||||
type I1 interface {
|
||||
I0;
|
||||
F, G (x float) float;
|
||||
F(x float) float;
|
||||
G(x float) float;
|
||||
}
|
||||
|
10
src/pkg/go/printer/testdata/declarations.go
vendored
10
src/pkg/go/printer/testdata/declarations.go
vendored
@ -215,18 +215,18 @@ type _ interface {
|
||||
|
||||
type _ interface {
|
||||
f();
|
||||
fffff, g ();
|
||||
fffff();
|
||||
}
|
||||
|
||||
type _ interface {
|
||||
EI;
|
||||
f();
|
||||
fffff, g ();
|
||||
fffffg();
|
||||
}
|
||||
|
||||
type _ interface { // this comment must not change indentation
|
||||
EI; // here's a comment
|
||||
f(); // no blank between f and ()
|
||||
fffff, g (); // blank between identifiers and ()
|
||||
gggggggggggg, hhhhhhhhhhhhhh (x, y, z int) (); // hurray
|
||||
f(); // no blank between identifier and ()
|
||||
fffff(); // no blank between identifier and ()
|
||||
gggggggggggg(x, y, z int) (); // hurray
|
||||
}
|
||||
|
12
src/pkg/go/printer/testdata/declarations.golden
vendored
12
src/pkg/go/printer/testdata/declarations.golden
vendored
@ -209,18 +209,18 @@ type _ interface {
|
||||
|
||||
type _ interface {
|
||||
f();
|
||||
fffff, g ();
|
||||
fffff();
|
||||
}
|
||||
|
||||
type _ interface {
|
||||
EI;
|
||||
f();
|
||||
fffff, g ();
|
||||
fffffg();
|
||||
}
|
||||
|
||||
type _ interface { // this comment must not change indentation
|
||||
EI; // here's a comment
|
||||
f(); // no blank between f and ()
|
||||
fffff, g (); // blank between identifiers and ()
|
||||
gggggggggggg, hhhhhhhhhhhhhh (x, y, z int); // hurray
|
||||
EI; // here's a comment
|
||||
f(); // no blank between identifier and ()
|
||||
fffff(); // no blank between identifier and ()
|
||||
gggggggggggg(x, y, z int); // hurray
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user