mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: make Value.Interface return immutable data
Fixes #3134. R=golang-dev, r CC=golang-dev https://golang.org/cl/5713049
This commit is contained in:
parent
dc159fabff
commit
a72b87efa9
2 changed files with 22 additions and 0 deletions
|
|
@ -1743,3 +1743,15 @@ func isValid(v Value) {
|
|||
panic("zero Value")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlias(t *testing.T) {
|
||||
x := string("hello")
|
||||
v := ValueOf(&x).Elem()
|
||||
oldvalue := v.Interface()
|
||||
v.SetString("world")
|
||||
newvalue := v.Interface()
|
||||
|
||||
if oldvalue != "hello" || newvalue != "world" {
|
||||
t.Errorf("aliasing: old=%q new=%q, want hello, world", oldvalue, newvalue)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue