Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tcard opened this issue Oct 13, 2020 · 6 comments
Open
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@tcard
Copy link

tcard commented Oct 13, 2020

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

$ go version
go version devel +5b509d993d Tue Oct 13 08:36:41 2020 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOOS="darwin"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"

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.

@tcard
Copy link
Author

tcard commented Oct 13, 2020

I've done some internal digging already and I'd like to submit a fix, if that's OK.

@tcard tcard changed the title reflect: argument validation panics with ValueError, which is for method receivers reflect: Set: argument validation panics with ValueError, which is for receiver Oct 13, 2020
@go101
Copy link

go101 commented Oct 13, 2020

I also found this problem before: #29701 (comment)

I forget why I didn't submit it as a new issue.

@rsc
Copy link
Contributor

rsc commented Oct 13, 2020

For what it's worth, the receiver is an argument to a method.

@go101
Copy link

go101 commented Oct 13, 2020

Here the problem is the inverse, it makes the impression that the general argument is treated as the receiver.

@ianlancetaylor
Copy link
Contributor

@tcard Sure, send a fix. Thanks.

@ianlancetaylor ianlancetaylor added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Oct 13, 2020
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Oct 13, 2020
@gopherbot
Copy link

Change https://golang.org/cl/262157 mentions this issue: reflect: ValueError: acknowledge it applies to non-receiver arguments

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
Status: Triage Backlog
Development

No branches or pull requests

5 participants