You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What does 'go version' print?
go version go1.3 linux/amd64
What steps reproduce the problem?
1. Create a value with kind `Interface`, holding an addressable value
2. Reflect the container value using reflect.ValueOf
3. Query addressability of contained value
See http://play.golang.org/p/uM5mwL1zxW for running example.
What happened?
false returned
What should have happened instead?
true returned
Please provide any additional information below.
This originated from http://stackoverflow.com/questions/24471907.
The reason for this behaviour is that Value.Elem() fails to pass on flagAddr to the
newly created Value:
https://code.google.com/p/go/source/browse/src/pkg/reflect/value.go?name=go1.3#844
The text was updated successfully, but these errors were encountered:
This seems to me to be correct. You have a []interface{}. You can take the address of
element 0 and you can set element 0. But what your program is trying to do is to take
the address of the value stored in the interface{} that is element 0, and that you can
not do. There is no way to write Go code to do that.
Moreover, if you could do it, then you could, in different code, change the interface
value to hold different type, and then you would have a pointer to the interior of an
interface that was not the type of the value actually stored in the interface. So if
this were permitted it would not be type safe.
OK, when you put it that way it makes sense. I guess my intuition failed me on that
because reflection *knows* the underlying type so it is *possible* (but obviously not
implemented) to return a typed pointer to the underlying value of the interface{} value
which would prevent another type being put into the interface{} value.
Since there is no equivalent Go code for this reflection feature it is unlikely to be
ever implemented. Thanks for the clarification.
by pronox:
The text was updated successfully, but these errors were encountered: