]> Cypherpunks repositories - gostls13.git/commitdiff
bug fix: allow function types as operands
authorRobert Griesemer <gri@golang.org>
Tue, 15 Sep 2009 23:16:34 +0000 (16:16 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 15 Sep 2009 23:16:34 +0000 (16:16 -0700)
R=rsc
DELTA=10  (5 added, 0 deleted, 5 changed)
OCL=34662
CL=34666

src/pkg/go/parser/parser.go

index 3ed25065f79b4d7e35a5704485dab571748ad18c..76682db950703530eb7d6f7619236b0b40597494 100644 (file)
@@ -873,12 +873,17 @@ func (p *parser) parseStringList(x *ast.BasicLit) []*ast.BasicLit {
 }
 
 
-func (p *parser) parseFuncLit() ast.Expr {
+func (p *parser) parseFuncTypeOrLit() ast.Expr {
        if p.trace {
-               defer un(trace(p, "FuncLit"));
+               defer un(trace(p, "FuncTypeOrLit"));
        }
 
        typ := p.parseFuncType();
+       if p.tok != token.LBRACE {
+               // function type only
+               return typ;
+       }
+
        p.exprLev++;
        body := p.parseBlockStmt(nil);
        p.optSemi = false;  // function body requires separating ";"
@@ -918,10 +923,10 @@ func (p *parser) parseOperand() ast.Expr {
                return &ast.ParenExpr{lparen, x, rparen};
 
        case token.FUNC:
-               return p.parseFuncLit();
+               return p.parseFuncTypeOrLit();
 
        default:
-               t := p.tryRawType(true);  // could be type for composite literal
+               t := p.tryRawType(true);  // could be type for composite literal or conversion
                if t != nil {
                        return t;
                }