mirror of
https://github.com/golang/go
synced 2024-11-26 07:38:00 -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:
parent
2e64511ac9
commit
f38f862417
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user