From d12c62d12dc87a086815ca9d8beaa8f0c8e26b00 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Wed, 11 Sep 2019 07:22:35 +0000 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- src/go/parser/interface.go | 2 +- src/go/parser/parser_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/go/parser/interface.go b/src/go/parser/interface.go index 9de160a798..0c3f824c98 100644 --- a/src/go/parser/interface.go +++ b/src/go/parser/interface.go @@ -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)") } diff --git a/src/go/parser/parser_test.go b/src/go/parser/parser_test.go index fb35a88ba1..18c05bce20 100644 --- a/src/go/parser/parser_test.go +++ b/src/go/parser/parser_test.go @@ -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)