Skip to content

Commit

Permalink
Merge pull request #1512 from visualfc/parser_leak
Browse files Browse the repository at this point in the history
parser: parseGlobalStmts EOF check
  • Loading branch information
xushiwei authored Nov 2, 2023
2 parents f493c2e + 91180f1 commit 1972a4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 '}'`, ``)
}

// -----------------------------------------------------------------------------

0 comments on commit 1972a4e

Please sign in to comment.