mirror of
https://github.com/golang/go.git
synced 2025-11-02 09:40:56 +00:00
context: document that WithValue's key must be comparable
Also, check it and explode earlier, rather than cryptic failures later. Change-Id: I319a425f60e2bc9d005a187fbdbd153faa96411c Reviewed-on: https://go-review.googlesource.com/21799 Reviewed-by: Andrew Gerrand <adg@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Minux Ma <minux@golang.org>
This commit is contained in:
parent
e6a8daceb0
commit
bd72497666
3 changed files with 21 additions and 2 deletions
|
|
@ -586,3 +586,16 @@ func TestCancelRemoves(t *testing.T) {
|
|||
cancel()
|
||||
checkChildren("after cancelling WithTimeout child", ctx, 0)
|
||||
}
|
||||
|
||||
func TestWithValueChecksKey(t *testing.T) {
|
||||
panicVal := recoveredValue(func() { WithValue(Background(), []byte("foo"), "bar") })
|
||||
if panicVal == nil {
|
||||
t.Error("expected panic")
|
||||
}
|
||||
}
|
||||
|
||||
func recoveredValue(fn func()) (v interface{}) {
|
||||
defer func() { v = recover() }()
|
||||
fn()
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue