]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types: don't report errors referring to invalid types or operands
authorRobert Griesemer <gri@golang.org>
Wed, 6 Jun 2018 18:36:35 +0000 (11:36 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 6 Jun 2018 19:20:12 +0000 (19:20 +0000)
Such errors are likely spurious and caused by previously reported
errors; they don't add valuable information. Simply drop them.

Fixes #24182.

Change-Id: I0ac48c41647c628aa7636b29eaedfd9d01913762
Reviewed-on: https://go-review.googlesource.com/116735
Reviewed-by: Alan Donovan <adonovan@google.com>
src/go/types/errors.go

index 0c0049b1f3e21185374a736203b30a37711e21a8..4c8d8537ee6a6e2989d6716e45117077814f203a 100644 (file)
@@ -67,10 +67,20 @@ func (check *Checker) dump(format string, args ...interface{}) {
 }
 
 func (check *Checker) err(pos token.Pos, msg string, soft bool) {
+       // Cheap trick: Don't report errors with messages containing
+       // "invalid operand" or "invalid type" as those tend to be
+       // follow-on errors which don't add useful information. Only
+       // exclude them if these strings are not at the beginning,
+       // and only if we have at least one error already reported.
+       if check.firstErr != nil && (strings.Index(msg, "invalid operand") > 0 || strings.Index(msg, "invalid type") > 0) {
+               return
+       }
+
        err := Error{check.fset, pos, msg, soft}
        if check.firstErr == nil {
                check.firstErr = err
        }
+
        f := check.conf.Error
        if f == nil {
                panic(bailout{}) // report only first error