From 63dcab2e91cfa40ae6dc1f0455b1f3c2801a00ec Mon Sep 17 00:00:00 2001 From: Tim King Date: Tue, 25 May 2021 19:23:02 -0700 Subject: [PATCH] doc/go1.17: mention new vet checks sigchanyzer and stdmethods. These vet checks were added in CL 299532 and CL 321389. Also adds a TODO for buildtags. Change-Id: I516dc77729f6d2dc147318260fe452831b115dfa Reviewed-on: https://go-review.googlesource.com/c/go/+/322769 Trust: Tim King Run-TryBot: Tim King TryBot-Result: Go Bot Reviewed-by: Dmitri Shuralyov --- doc/go1.17.html | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/doc/go1.17.html b/doc/go1.17.html index eb7932cd67..cc3bcdf180 100644 --- a/doc/go1.17.html +++ b/doc/go1.17.html @@ -277,14 +277,55 @@ Do not send CLs removing the interior tags from such phrases.

Vet

+

New warning within buildtags

+ +

+ TODO(rsc): Describe changes to buildtags https://golang.org/cl/240609 +

+ +

New warning for calling signal.Notify on unbuffered channels

+

- TODO: https://golang.org/cl/299532: cmd/vet: bring in sigchanyzer to report unbuffered channels to signal.Notify + The vet tool now warns about calls to signal.Notify + with incoming signals being sent to an unbuffered channel. Using an unbuffered channel + risks missing signals sent on them as signal.Notify does not block when + sending to a channel. For example:

+
+c := make(chan os.Signal)
+// signals are sent on c before the channel is read from.
+// This signal may be dropped as c is unbuffered.
+signal.Notify(c, os.Interrupt)
+
+

- TODO: complete the Vet section + Users of signal.Notify should use channels with sufficient buffer space to keep up with the + expected signal rate.

+

New warnings for Is, As and Unwrap methods

+ +

+ The vet tool now warns about methods named As, Is or Unwrap + on types implementing the error interface that have a different signature than the + one expected by the errors package. The errors.{As,Is,Unwrap} functions + expect such methods to implement either Is(error) bool, + As(interface{}) bool, or Unwrap() error + respectively. The functions errors.{As,Is,Unwrap} will ignore methods with the same + names but a different signature. For example: +

+ +
+type MyError struct { hint string }
+func (m MyError) Error() string { ... } // MyError implements error.
+func (MyError) Is(target interface{}) bool { ... } // target is interface{} instead of error.
+func Foo() bool {
+	x, y := MyError{"A"}, MyError{"B"}
+	return errors.Is(x, y) // returns false as x != y and MyError does not have an `Is(error) bool` function.
+}
+
+

Cover

-- 2.50.0