From fe076c893b67efab5ab7960884cc27aa5beb9394 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Mon, 20 Sep 2021 15:14:52 -0400 Subject: [PATCH] internal/typesinternal: document ReadGo116ErrorData Change-Id: I5afe3e4d3f137758da404e779d6bc9b0a57b6a02 Reviewed-on: https://go-review.googlesource.com/c/tools/+/351089 Trust: Robert Findley Run-TryBot: Robert Findley gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Rebecca Stambler --- internal/typesinternal/types.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/typesinternal/types.go b/internal/typesinternal/types.go index c3e1a397db..7c77c2fbc0 100644 --- a/internal/typesinternal/types.go +++ b/internal/typesinternal/types.go @@ -30,10 +30,15 @@ func SetUsesCgo(conf *types.Config) bool { return true } -func ReadGo116ErrorData(terr types.Error) (ErrorCode, token.Pos, token.Pos, bool) { +// ReadGo116ErrorData extracts additional information from types.Error values +// generated by Go version 1.16 and later: the error code, start position, and +// end position. If all positions are valid, start <= err.Pos <= end. +// +// If the data could not be read, the final result parameter will be false. +func ReadGo116ErrorData(err types.Error) (code ErrorCode, start, end token.Pos, ok bool) { var data [3]int // By coincidence all of these fields are ints, which simplifies things. - v := reflect.ValueOf(terr) + v := reflect.ValueOf(err) for i, name := range []string{"go116code", "go116start", "go116end"} { f := v.FieldByName(name) if !f.IsValid() {