diff --git a/parser/parser.go b/parser/parser.go index 5914f55bd..2fc8a509c 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -3647,6 +3647,9 @@ func (p *parser) parseGlobalStmts(sync map[token.Token]bool, pos token.Pos, stmt if p.errors.Len() != 0 { // TODO: error p.advance(sync) } + if p.tok != token.EOF { + p.errorExpected(p.pos, "statement", 2) + } f := &ast.FuncDecl{ Name: &ast.Ident{NamePos: pos, Name: "main"}, Doc: doc, diff --git a/parser/parser_test.go b/parser/parser_test.go index 76fe912dd..bb6c4bb13 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -508,4 +508,9 @@ const d `, `/foo/bar.gox:5:7: missing constant value`, ``) } +func TestErrGlobal(t *testing.T) { + testErrCode(t, `func test() {} +}`, `/foo/bar.gop:2:1: expected statement, found '}'`, ``) +} + // -----------------------------------------------------------------------------