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: fix deep equal bug on comparing func types #27758

Closed
wants to merge 2 commits into from

Conversation

everdance
Copy link

deepEqual function only compare nil values for func types, need also compare func pointer address.
bug example:
https://play.golang.org/p/TKKxpYIzs9W

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@googlebot googlebot added the cla: no Used by googlebot to label PRs as having an invalid CLA. The text of this label should not change. label Sep 19, 2018
@everdance
Copy link
Author

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.

What to do if you already signed the CLA

Individual signers
Corporate signers

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change. and removed cla: no Used by googlebot to label PRs as having an invalid CLA. The text of this label should not change. labels Sep 19, 2018
@gopherbot
Copy link

This PR (HEAD: 42a93a2) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/136335 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Gerrit User 5976:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
Within the next week or so, a maintainer will review your change and provide
feedback. See https://golang.org/doc/contribute.html#review for more info and
tips to get your patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11, it means that this CL will be reviewed as part of the next development
cycle. See https://golang.org/s/release for more details.


Please don’t reply on this GitHub thread. Visit golang.org/cl/136335.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: 5cab472) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/136335 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Gerrit User 7435:

Patch Set 2:

I don't think this is correct. The language specification only allows comparing functions with nil, so reflect.DeepEqual should not do more than that.


Please don’t reply on this GitHub thread. Visit golang.org/cl/136335.
After addressing review feedback, remember to publish your drafts!

@everdance
Copy link
Author

everdance commented Sep 19, 2018

then we need change the language specification, how it can be logically sound that you can do f1 := func() {}; fn2 := f1 but not f2 == f1

@randall77
Copy link
Contributor

The language spec already covers this:

Slice, map, and function values are not comparable. However, as a special case, a slice, map, or function value may be compared to the predeclared identifier nil.

So this code won't even compile:

var a func()
var b func()
var c = a == b

deepEqual is in kind of a tough spot here, because it's being asked to do something - compare two values of function type - when the language spec declares such comparisons to be illegal. Not just having an undefined result, but it's a question you're not allowed to ask. deepEqual chose false as the answer. Another possible answer is to panic, but that has its own issues.

What would you have deepEqual do instead? Comparing the function address isn't enough - some functions might be closures. And due to the way shared library linking is done, identical references to the same function in different packages might have different function addresses (one would be the address of a trampoline that jumps to the other).

@everdance
Copy link
Author

ok, it's way more complicated. close this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants