Skip to content

reflect.Value.Set error for embed struct #1163

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
visualfc opened this issue Oct 18, 2022 · 0 comments · Fixed by #1164
Closed

reflect.Value.Set error for embed struct #1163

visualfc opened this issue Oct 18, 2022 · 0 comments · Fixed by #1164

Comments

@visualfc
Copy link
Contributor

visualfc commented Oct 18, 2022

  • main.go
package main

import (
	"fmt"
	"reflect"
)

func main() {
	c := &A{}
	c.value = true
	c.point = Point{100, 200}
	in := reflect.ValueOf(c).Elem()
	v := reflect.New(in.Type())
	e := v.Elem()
	f0 := e.Field(0)
	e.Set(in)
	fmt.Println(e.Field(0), f0, e.Field(0) == f0)
}

type Point struct {
	x int
	y int
}

type Embed struct {
	value bool
	point Point
}

type A struct {
	Embed
}
  • go run main.go
{true {100 200}} {true {100 200}} true
  • gopherjs run main.go
{true {100 200}} {false {0 0}} false

reflect.Value.Set error no sync with embed field.

@visualfc visualfc changed the title reflect.Set error for embed struct reflect.Value.Set error for embed struct Oct 19, 2022
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 a pull request may close this issue.

1 participant