File tree 2 files changed +27
-3
lines changed
compiler/natives/src/reflect
2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -1436,12 +1436,10 @@ func (v Value) Set(x Value) {
1436
1436
x = x .assignTo ("reflect.Set" , v .typ , nil )
1437
1437
if v .flag & flagIndir != 0 {
1438
1438
switch v .typ .Kind () {
1439
- case Array :
1439
+ case Array , Struct :
1440
1440
jsType (v .typ ).Call ("copy" , js .InternalObject (v .ptr ), js .InternalObject (x .ptr ))
1441
1441
case Interface :
1442
1442
js .InternalObject (v .ptr ).Call ("$set" , js .InternalObject (valueInterface (x , false )))
1443
- case Struct :
1444
- copyStruct (js .InternalObject (v .ptr ), js .InternalObject (x .ptr ), v .typ )
1445
1443
default :
1446
1444
js .InternalObject (v .ptr ).Call ("$set" , x .object ())
1447
1445
}
Original file line number Diff line number Diff line change @@ -862,3 +862,29 @@ func TestVersion(t *testing.T) {
862
862
t .Fatalf ("Got: runtime.Version() returned %q. Want: a valid Go version." , got )
863
863
}
864
864
}
865
+
866
+ // https://github.com/gopherjs/gopherjs/issues/1163
867
+ func TestReflectSetForEmbed (t * testing.T ) {
868
+ type Point struct {
869
+ x int
870
+ y int
871
+ }
872
+ type Embed struct {
873
+ value bool
874
+ point Point
875
+ }
876
+ type A struct {
877
+ Embed
878
+ }
879
+ c := & A {}
880
+ c .value = true
881
+ c .point = Point {100 , 200 }
882
+ in := reflect .ValueOf (c ).Elem ()
883
+ v := reflect .New (in .Type ())
884
+ e := v .Elem ()
885
+ f0 := e .Field (0 )
886
+ e .Set (in )
887
+ if e .Field (0 ) != f0 {
888
+ t .Fatalf ("relfect.Set got %v, want %v" , f0 , e .Field (0 ))
889
+ }
890
+ }
You can’t perform that action at this time.
0 commit comments