Change-Id: I2e8ae403622ba7131cadaba506100d79613183f1
Reviewed-on: https://go-review.googlesource.com/22601
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
//
// The provided key must be comparable.
func WithValue(parent Context, key, val interface{}) Context {
+ if key == nil {
+ panic("nil key")
+ }
if !reflect.TypeOf(key).Comparable() {
panic("key is not comparable")
}
if panicVal == nil {
t.Error("expected panic")
}
+ panicVal = recoveredValue(func() { WithValue(Background(), nil, "bar") })
+ if got, want := fmt.Sprint(panicVal), "nil key"; got != want {
+ t.Errorf("panic = %q; want %q", got, want)
+ }
}
func recoveredValue(fn func()) (v interface{}) {