Skip to content

Conversation

@visualfc
Copy link
Contributor

fix #1156

@nevkontakte
Copy link
Member

A couple of questions:

  • Should the copy happen when Value.Index() or Value.Interface() method is called? I think in the equivalent non-reflect code the copy would happen on the index operation.
  • Does reflectlite have the same bug? If so, maybe fix it as well?

@visualfc
Copy link
Contributor Author

A couple of questions:

  • Should the copy happen when Value.Index() or Value.Interface() method is called? I think in the equivalent non-reflect code the copy would happen on the index operation.

copy struct on reflect.Value to interface time.
v.Index(0) == a[0]

	a := []student{student{"A"}, student{"B"}, student{"C"}}
	v := reflect.ValueOf(a)
	i := v.Index(0)
        j := i.Interface()
	a[0] = student{"X"}
	fmt.Println(a, i, j)
        // output [{X} {B} {C}] {X} {A}
  • Does reflectlite have the same bug? If so, maybe fix it as well?

sync with reflect

@nevkontakte nevkontakte merged commit 5214468 into gopherjs:master Sep 29, 2022
@nevkontakte
Copy link
Member

Thank you for your contribution!

@visualfc visualfc deleted the valueinterface branch September 29, 2022 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reflect value.Interface not copy for struct

2 participants