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
See code at http://play.golang.org/p/MIkFP_Zrxb
What does 'go version' print?
go version go1.2.1 darwin/amd64
What steps reproduce the problem?
Calling reflect.SetMapIndex() causes changes to the key that prevent future calls to
SetMapIndex from working.
If possible, include a link to a program on play.golang.org.
http://play.golang.org/p/MIkFP_Zrxb
What happened?
1. Run the linked code.
2. Notice that the key after the call to SetMapIndex is different
3. Notice that the second call to SetMapIndex doesn't work.
What should have happened instead?
The key should be unchanged and both calls to SetMapIndex should work.
Code copied below:
package main
import (
"fmt"
"reflect"
)
func main() {
m1 := map[string]bool{"a": true, "b": true}
m2 := map[string]bool{"a": true, "b": true}
fmt.Println(m1)
v1 := reflect.ValueOf(m1)
k := v1.MapKeys()[0]
fmt.Println("KEY BEFORE", k)
v1.SetMapIndex(k, reflect.Value{}) // COMMENT THIS OUT
fmt.Println("m1:", m1)
fmt.Println("KEY AFTER", k)
v2 := reflect.ValueOf(m2)
v2.SetMapIndex(k, reflect.Value{})
fmt.Println("KEY AFTER SECOND CALL", k)
fmt.Println("m2:", m2)
}
The text was updated successfully, but these errors were encountered:
http://play.golang.org/p/EtZmoIyYPz
Because you removed key "a" from the map, it makes sense that the prior key value isn't
valid anymore.
I think this is a documentation issue.
If this is WAI, it's a pretty awkward API. The behavior of SetMapIndex depends on 1) the
origin of the key value, and 2) the order of the SetMapIndex calls. Both of these could
lead to some very difficult to find bugs.
http://play.golang.org/p/8HY4i0N8_z
by gmadrid:
The text was updated successfully, but these errors were encountered: