golang/go

reflect: Set: argument validation panics with ValueError, which is for receiver

Open

#41,953 opened on Oct 13, 2020

View on GitHub
 (6 comments) (0 reactions) (0 assignees)Go (19,008 forks)batch import
NeedsFixcompiler/runtimehelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

What version of Go are you using (go version)?

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

What did you do?

Pass a zero reflect.Value to Value.Set, as an argument.

https://play.golang.org/p/hynNVbNp4-L

What did you expect to see?

An error that puts the culprit on Value.Set's argument, not on its receiver. Something like:

panic: reflect: zero Value passed to reflect.Value.Set

What did you see instead?

A ValueError like this:

panic: reflect: call of reflect.Value.Set on zero Value

According to the docs:

A ValueError occurs when a Value method is invoked on a Value that does not support it. Such cases are documented in the description of each method.

But that's not what's really happening here. The receiving Value does support Set. It's the argument which is wrong.

Contributor guide