1
0
mirror of https://github.com/golang/go synced 2024-11-26 09:28:07 -07:00

[dev.typeparams] go/types: strip annotations from errors

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>
This commit is contained in:
Rob Findley 2021-01-15 11:23:28 -05:00 committed by Robert Findley
parent 2e64511ac9
commit f38f862417

View File

@ -89,7 +89,9 @@ func (check *Checker) err(err error) {
return return
} }
if check.errpos != nil && isInternal { 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 // If we have an internal error and the errpos override is set, use it to
// augment our error positioning. // augment our error positioning.
// TODO(rFindley) we may also want to augment the error message and refer // TODO(rFindley) we may also want to augment the error message and refer
@ -98,6 +100,7 @@ func (check *Checker) err(err error) {
e.Pos = span.pos e.Pos = span.pos
e.go116start = span.start e.go116start = span.start
e.go116end = span.end e.go116end = span.end
}
err = e err = e
} }
@ -225,3 +228,18 @@ func spanOf(at positioner) posSpan {
return posSpan{pos, pos, pos} 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
}