Thanks to visit codestin.com
Credit goes to github.com

Skip to content

compiler/natives/src/reflect: fix valueIntrface check struct copy #1157

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

Merged
merged 4 commits into from
Sep 29, 2022

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