]> Cypherpunks repositories - gostls13.git/commitdiff
permit only one method name per method signature in interface types
authorRobert Griesemer <gri@golang.org>
Mon, 28 Sep 2009 21:54:53 +0000 (14:54 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 28 Sep 2009 21:54:53 +0000 (14:54 -0700)
(in sync with spec CL 35047)

R=rsc
DELTA=44  (4 added, 8 deleted, 32 changed)
OCL=35048
CL=35054

src/pkg/go/parser/parser.go
src/pkg/go/printer/printer.go
src/pkg/go/printer/testdata/comments.go
src/pkg/go/printer/testdata/comments.golden
src/pkg/go/printer/testdata/comments.x
src/pkg/go/printer/testdata/declarations.go
src/pkg/go/printer/testdata/declarations.golden

index d3be849b51a11317b0936c3775419e91551048c9..034ee80994861fe4bdb6482bda8d3f522263df75 100644 (file)
@@ -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 {
index 3c9f32405c97bf8b73762c8ef9cf002751a171c7..21c89128900d28dc2e46387865de38f2ca2ad6c7 100644 (file)
@@ -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
index 690da6bbef7d9a49dd20b192ce2e4bf3f5016bad..271886d7206acc576786d34a10b4cd8790aae420 100644 (file)
@@ -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
index 2d37c5d2657402d873d1c3781d1f39a980a4c6c4..40f81c194e9f48648c905121d5fb15288c25fdaa 100644 (file)
@@ -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
index 98c57a40cedf63d46d47ef41088e3e94aeecb607..9450119c68e99d3cfb940d11c2412b3f62f71b72 100644 (file)
@@ -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;
 }
index 4ad78fe0eb7bb852f0a1f78cd8b818e9ac79c5ad..e853eb55c7eafcfaa8c1557dbdda38ee35ce907a 100644 (file)
@@ -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
 }
index 6ab45db745c4a20752b5277f1c1952eef6b2191c..4181b05ecd706a2ad2266b9e1ee1aa6e388de3f0 100644 (file)
@@ -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
 }