mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: allow unexported key in Value.MapIndex
Fixes #1748. R=golang-dev, r CC=golang-dev https://golang.org/cl/4444087
This commit is contained in:
parent
8ef56f7e92
commit
86e6a44112
2 changed files with 25 additions and 2 deletions
|
|
@ -958,14 +958,19 @@ func (v Value) MapIndex(key Value) Value {
|
|||
iv.mustBe(Map)
|
||||
typ := iv.typ.toType()
|
||||
|
||||
// Do not require ikey to be exported, so that DeepEqual
|
||||
// and other programs can use all the keys returned by
|
||||
// MapKeys as arguments to MapIndex. If either the map
|
||||
// or the key is unexported, though, the result will be
|
||||
// considered unexported.
|
||||
|
||||
ikey := key.internal()
|
||||
ikey.mustBeExported()
|
||||
ikey = convertForAssignment("reflect.Value.MapIndex", nil, typ.Key(), ikey)
|
||||
if iv.word == 0 {
|
||||
return Value{}
|
||||
}
|
||||
|
||||
flag := iv.flag & flagRO
|
||||
flag := (iv.flag | ikey.flag) & flagRO
|
||||
elemType := typ.Elem()
|
||||
elemWord, ok := mapaccess(iv.word, ikey.word)
|
||||
if !ok {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue