]> Cypherpunks repositories - gostls13.git/commitdiff
go/parser: fix scoping for local type declarations
authorRoger Peppe <rogpeppe@gmail.com>
Wed, 30 Mar 2011 16:45:51 +0000 (09:45 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 30 Mar 2011 16:45:51 +0000 (09:45 -0700)
R=gri
CC=golang-dev
https://golang.org/cl/4332045

src/pkg/go/parser/parser.go

index ad7e4cdcf2e2856ef798df8e01c75517350b86a8..5b1edace1b6cfbcee28fca1f17146c49bff947ee 100644 (file)
@@ -2016,16 +2016,17 @@ func parseTypeSpec(p *parser, doc *ast.CommentGroup, _ int) ast.Spec {
        }
 
        ident := p.parseIdent()
-       typ := p.parseType()
-       p.expectSemi() // call before accessing p.linecomment
 
        // Go spec: The scope of a type identifier declared inside a function begins
        // at the identifier in the TypeSpec and ends at the end of the innermost
        // containing block.
        // (Global identifiers are resolved in a separate phase after parsing.)
-       spec := &ast.TypeSpec{doc, ident, typ, p.lineComment}
+       spec := &ast.TypeSpec{doc, ident, nil, p.lineComment}
        p.declare(spec, p.topScope, ast.Typ, ident)
 
+       spec.Type = p.parseType()
+       p.expectSemi() // call before accessing p.linecomment
+
        return spec
 }