1
0
mirror of https://github.com/golang/go synced 2024-11-05 15:16:11 -07:00

go/parser: fix ignored errors in ParseExprFrom

This CL fixes a bug in ParseExprFrom which makes
error messages ignored when there are 10+ errors
in a single expression.

fixes #34241
fixes #34274

Change-Id: I29a82d3e3e726279005eb6fbcd7ee3aebffaa679
Reviewed-on: https://go-review.googlesource.com/c/go/+/194638
Run-TryBot: Ben Shi <powerman1st@163.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Ben Shi 2019-09-11 07:22:35 +00:00 committed by Robert Griesemer
parent 4e215554aa
commit d12c62d12d
2 changed files with 17 additions and 1 deletions

View File

@ -173,7 +173,7 @@ func ParseDir(fset *token.FileSet, path string, filter func(os.FileInfo) bool, m
// be a valid Go (type or value) expression. Specifically, fset must not
// be nil.
//
func ParseExprFrom(fset *token.FileSet, filename string, src interface{}, mode Mode) (ast.Expr, error) {
func ParseExprFrom(fset *token.FileSet, filename string, src interface{}, mode Mode) (expr ast.Expr, err error) {
if fset == nil {
panic("parser.ParseExprFrom: no token.FileSet provided (fset == nil)")
}

View File

@ -42,6 +42,22 @@ func nameFilter(filename string) bool {
func dirFilter(f os.FileInfo) bool { return nameFilter(f.Name()) }
func TestParseFile(t *testing.T) {
src := "package p\nvar _=s[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]"
_, err := ParseFile(token.NewFileSet(), "", src, 0)
if err == nil {
t.Errorf("ParseFile(%s) succeeded unexpectedly", src)
}
}
func TestParseExprFrom(t *testing.T) {
src := "s[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]"
_, err := ParseExprFrom(token.NewFileSet(), "", src, 0)
if err == nil {
t.Errorf("ParseExprFrom(%s) succeeded unexpectedly", src)
}
}
func TestParseDir(t *testing.T) {
path := "."
pkgs, err := ParseDir(token.NewFileSet(), path, dirFilter, 0)