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

encoding/gob: more detail in interface assignment error message #6467

Closed
btracey opened this issue Sep 24, 2013 · 7 comments
Closed

encoding/gob: more detail in interface assignment error message #6467

btracey opened this issue Sep 24, 2013 · 7 comments
Milestone

Comments

@btracey
Copy link
Contributor

@btracey btracey commented Sep 24, 2013

I was hoping

// setInterfaceValue sets an interface value to a concrete value,
// but first it checks that the assignment will succeed.
func setInterfaceValue(ivalue reflect.Value, value reflect.Value) {
    if !value.Type().AssignableTo(ivalue.Type()) {
        errorf("cannot assign value of type %s to %s", value.Type(), ivalue.Type())
    }
    ivalue.Set(value)
}

Could be changed to 
errorf("%s is not assignable to type %s", value.Type(), ivalue.Type(),
value.Type(), ivalue.Type())

I feel that the documentation on gob could be improved, though from previous discussions
it sounds like there is disagreement on adding examples for interfaces. While perhaps
independently this error seems sufficient, I found it confusing in the set of errors I
encountered while trying to understand how to correctly use the interface encoding, and
I did not fully realize what that meant until I looked at the source to see
reflect.AssignableTo was being used. I feel like changing the wording in this way makes
it more clear that "assign" is being used like in the language of the spec,
and not in a less precise manner.
@rsc
Copy link
Contributor

@rsc rsc commented Oct 18, 2013

Comment 1:

Status changed to Duplicate.

Merged into issue #3353.

@rsc
Copy link
Contributor

@rsc rsc commented Oct 18, 2013

Comment 2:

Labels changed: added priority-later, go1.3, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

@rsc rsc commented Dec 4, 2013

Comment 3:

Labels changed: added release-go1.3.

@rsc
Copy link
Contributor

@rsc rsc commented Dec 4, 2013

Comment 4:

Labels changed: removed go1.3.

@rsc
Copy link
Contributor

@rsc rsc commented Dec 4, 2013

Comment 5:

Labels changed: added repo-main.

@kelseyhightower
Copy link
Contributor

@kelseyhightower kelseyhightower commented Mar 5, 2014

Comment 6:

I've submitted a CL for this issue: https://golang.org/cl/71590043
@robpike
Copy link
Contributor

@robpike robpike commented Mar 5, 2014

Comment 7:

This issue was closed by revision 13e359b.

Status changed to Fixed.

@btracey btracey added fixed labels Mar 5, 2014
@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.