internal/memoize: show key type in panics

gopls uses a lot of keys that are just strings, which print without any
type information. Include the type of the key explicitly.

Updates golang/go#41415.

Change-Id: I01cfc685184e7b44c1f562b6536f173da5ae4830
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255357
Trust: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Heschi Kreinick 2020-09-16 14:10:10 -04:00
parent 587cf2330c
commit f128e626db
1 changed files with 2 additions and 2 deletions

View File

@ -228,7 +228,7 @@ func (g *Generation) Inherit(h *Handle) {
h.mu.Lock()
defer h.mu.Unlock()
if h.state == stateDestroyed {
panic(fmt.Sprintf("inheriting destroyed handle %#v into generation %v", h.key, g.name))
panic(fmt.Sprintf("inheriting destroyed handle %#v (type %T) into generation %v", h.key, h.key, g.name))
}
h.generations[g] = struct{}{}
}
@ -280,7 +280,7 @@ func (h *Handle) Get(ctx context.Context, g *Generation, arg Arg) (interface{},
return h.value, nil
case stateDestroyed:
h.mu.Unlock()
err := fmt.Errorf("Get on destroyed entry %#v in generation %v", h.key, g.name)
err := fmt.Errorf("Get on destroyed entry %#v (type %T) in generation %v", h.key, h.key, g.name)
if *panicOnDestroyed {
panic(err)
}