aboutsummaryrefslogtreecommitdiff
path: root/src/go/parser/parser.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2019-10-21 15:29:41 -0700
committerRobert Griesemer <gri@golang.org>2019-10-21 23:36:02 +0000
commita59808ed01b52119025c49c7ab71ceffbf56c080 (patch)
tree63f224aa1edc3d6f5209fa12b7de419ea756c12d /src/go/parser/parser.go
parent6b3bb4ba3bcc190200af4f1eedf454658094097f (diff)
downloadgo-a59808ed01b52119025c49c7ab71ceffbf56c080.tar.gz
go-a59808ed01b52119025c49c7ab71ceffbf56c080.zip
go/parser: better error (recovery) for Allman/BSD-style func decls
This matches the behavior and error of cmd/compile. Fixes #34946. Change-Id: I329ef358deea63d8425f76f1d54c95749b96c365 Reviewed-on: https://go-review.googlesource.com/c/go/+/202484 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/go/parser/parser.go')
-rw-r--r--src/go/parser/parser.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go
index ba16b65224..35349611e8 100644
--- a/src/go/parser/parser.go
+++ b/src/go/parser/parser.go
@@ -2439,8 +2439,18 @@ func (p *parser) parseFuncDecl() *ast.FuncDecl {
var body *ast.BlockStmt
if p.tok == token.LBRACE {
body = p.parseBody(scope)
+ p.expectSemi()
+ } else if p.tok == token.SEMICOLON {
+ p.next()
+ if p.tok == token.LBRACE {
+ // opening { of function declaration on next line
+ p.error(p.pos, "unexpected semicolon or newline before {")
+ body = p.parseBody(scope)
+ p.expectSemi()
+ }
+ } else {
+ p.expectSemi()
}
- p.expectSemi()
decl := &ast.FuncDecl{
Doc: doc,