From f38f862417d19485468474646848d4294f8587b8 Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Fri, 15 Jan 2021 11:23:28 -0500 Subject: [PATCH] [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 TryBot-Result: Go Bot Reviewed-by: Robert Griesemer Trust: Robert Griesemer Trust: Robert Findley --- src/go/types/errors.go | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/go/types/errors.go b/src/go/types/errors.go index a2195011f0..a956256762 100644 --- a/src/go/types/errors.go +++ b/src/go/types/errors.go @@ -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 +} -- 2.48.1