time: panic with a more helpful error on use of invalid Timer
Fixes #8721
LGTM=rsc
R=r, rsc
CC=golang-codereviews
https://golang.org/cl/155620045
diff --git a/src/time/sleep.go b/src/time/sleep.go
index 61660d1..e7a2ee2 100644
--- a/src/time/sleep.go
+++ b/src/time/sleep.go
@@ -55,6 +55,9 @@
// Stop does not close the channel, to prevent a read from the channel succeeding
// incorrectly.
func (t *Timer) Stop() bool {
+ if t.r.f == nil {
+ panic("time: Stop called on uninitialized Timer")
+ }
return stopTimer(&t.r)
}
@@ -78,6 +81,9 @@
// It returns true if the timer had been active, false if the timer had
// expired or been stopped.
func (t *Timer) Reset(d Duration) bool {
+ if t.r.f == nil {
+ panic("time: Reset called on uninitialized Timer")
+ }
w := when(d)
active := stopTimer(&t.r)
t.r.when = w