Skip to content

reflect.Value.Set error for embed struct #1163

Closed
@visualfc

Description

@visualfc
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions