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
diff --git a/src/pkg/go/parser/parser.go b/src/pkg/go/parser/parser.go
index d3be849..034ee80 100644
--- a/src/pkg/go/parser/parser.go
+++ b/src/pkg/go/parser/parser.go
@@ -305,16 +305,13 @@
}
-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 @@
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 @@
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 @@
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 @@
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 {
diff --git a/src/pkg/go/printer/printer.go b/src/pkg/go/printer/printer.go
index 3c9f324..21c8912 100644
--- a/src/pkg/go/printer/printer.go
+++ b/src/pkg/go/printer/printer.go
@@ -610,12 +610,9 @@
} 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
diff --git a/src/pkg/go/printer/testdata/comments.go b/src/pkg/go/printer/testdata/comments.go
index 690da6b..271886d 100644
--- a/src/pkg/go/printer/testdata/comments.go
+++ b/src/pkg/go/printer/testdata/comments.go
@@ -42,20 +42,21 @@
// 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
diff --git a/src/pkg/go/printer/testdata/comments.golden b/src/pkg/go/printer/testdata/comments.golden
index 2d37c5d..40f81c1 100644
--- a/src/pkg/go/printer/testdata/comments.golden
+++ b/src/pkg/go/printer/testdata/comments.golden
@@ -42,20 +42,21 @@
// 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
diff --git a/src/pkg/go/printer/testdata/comments.x b/src/pkg/go/printer/testdata/comments.x
index 98c57a4..9450119 100644
--- a/src/pkg/go/printer/testdata/comments.x
+++ b/src/pkg/go/printer/testdata/comments.x
@@ -35,13 +35,13 @@
// 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;
}
diff --git a/src/pkg/go/printer/testdata/declarations.go b/src/pkg/go/printer/testdata/declarations.go
index 4ad78fe..e853eb5 100644
--- a/src/pkg/go/printer/testdata/declarations.go
+++ b/src/pkg/go/printer/testdata/declarations.go
@@ -215,18 +215,18 @@
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
}
diff --git a/src/pkg/go/printer/testdata/declarations.golden b/src/pkg/go/printer/testdata/declarations.golden
index 6ab45db..4181b05 100644
--- a/src/pkg/go/printer/testdata/declarations.golden
+++ b/src/pkg/go/printer/testdata/declarations.golden
@@ -209,18 +209,18 @@
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
}