Skip to content

reflect: Value.Interface() should return a copy of data for settable values #3134

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

Closed
remyoudompheng opened this issue Feb 26, 2012 · 3 comments
Milestone

Comments

@remyoudompheng
Copy link
Contributor

What steps will reproduce the problem?
1. Compile and run

package main

import (
      "fmt"
      "reflect"
)

func main() {
      x := string("hello")
      v := reflect.ValueOf(&x).Elem()
      oldvalue := v.Interface()
      v.SetString("world")
      newvalue := v.Interface()
      fmt.Println(oldvalue, newvalue)

      n := int64(1)
      v = reflect.ValueOf(&n).Elem()
      oldvalue = v.Interface()
      v.SetInt(2)
      newvalue = v.Interface()
      fmt.Println(oldvalue, newvalue)
}

What is the expected output? What do you see instead?

Expected:
hello world
1 2

Seen (GOARCH=386):
world world
2 2

Seen (GOARCH=amd64):
world world
1 2
@robpike
Copy link
Contributor

robpike commented Feb 26, 2012

Comment 1:

Labels changed: added go1-must, priority-go1, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Mar 1, 2012

Comment 2:

http://golang.org/cl/5713049

Owner changed to @rsc.

Status changed to Started.

@rsc
Copy link
Contributor

rsc commented Mar 1, 2012

Comment 3:

This issue was closed by revision a72b87e.

Status changed to Fixed.

@rsc rsc added this to the Go1 milestone Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants