]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.typeparams] go/types: strip annotations from errors
authorRob Findley <rfindley@google.com>
Fri, 15 Jan 2021 16:23:28 +0000 (11:23 -0500)
committerRobert Findley <rfindley@google.com>
Tue, 19 Jan 2021 21:29:12 +0000 (21:29 +0000)
Strip annotations from errors before emitting them. This is a partial
merge from dev.go2go: the Error.Full field is omitted for now, and
stripAnnotations is integrated with the updated error handling from
master.

Change-Id: Ia24d66b691a10d90b258b0b688d50c6b176bd629
Reviewed-on: https://go-review.googlesource.com/c/go/+/284253
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>

src/go/types/errors.go

index a2195011f0ee63a2f8c8459ce1617ff6cae212f0..a956256762f05cd2bde59bc949a269576f4e59a3 100644 (file)
@@ -89,15 +89,18 @@ func (check *Checker) err(err error) {
                return
        }
 
-       if check.errpos != nil && isInternal {
-               // If we have an internal error and the errpos override is set, use it to
-               // augment our error positioning.
-               // TODO(rFindley) we may also want to augment the error message and refer
-               // to the position (pos) in the original expression.
-               span := spanOf(check.errpos)
-               e.Pos = span.pos
-               e.go116start = span.start
-               e.go116end = span.end
+       if isInternal {
+               e.Msg = stripAnnotations(e.Msg)
+               if check.errpos != nil {
+                       // If we have an internal error and the errpos override is set, use it to
+                       // augment our error positioning.
+                       // TODO(rFindley) we may also want to augment the error message and refer
+                       // to the position (pos) in the original expression.
+                       span := spanOf(check.errpos)
+                       e.Pos = span.pos
+                       e.go116start = span.start
+                       e.go116end = span.end
+               }
                err = e
        }
 
@@ -225,3 +228,18 @@ func spanOf(at positioner) posSpan {
                return posSpan{pos, pos, pos}
        }
 }
+
+// stripAnnotations removes internal (type) annotations from s.
+func stripAnnotations(s string) string {
+       var b strings.Builder
+       for _, r := range s {
+               // strip #'s and subscript digits
+               if r != instanceMarker && !('₀' <= r && r < '₀'+10) { // '₀' == U+2080
+                       b.WriteRune(r)
+               }
+       }
+       if b.Len() < len(s) {
+               return b.String()
+       }
+       return s
+}