fix: assign composite literal by reference
This commit is contained in:
16
_test/composite8.go
Normal file
16
_test/composite8.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
type T struct{ I int }
|
||||
|
||||
func main() {
|
||||
t := []*T{}
|
||||
s := []int{1, 2}
|
||||
for _, e := range s {
|
||||
x := &T{e}
|
||||
t = append(t, x)
|
||||
}
|
||||
println(t[0].I, t[1].I)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 1 2
|
||||
@@ -1732,6 +1732,7 @@ func doCompositeLit(n *node, hasType bool) {
|
||||
}
|
||||
}
|
||||
|
||||
i := n.findex
|
||||
n.exec = func(f *frame) bltn {
|
||||
a := reflect.New(n.typ.TypeOf()).Elem()
|
||||
for i, v := range values {
|
||||
@@ -1743,7 +1744,7 @@ func doCompositeLit(n *node, hasType bool) {
|
||||
case destInterface:
|
||||
d.Set(reflect.ValueOf(valueInterface{n, a}))
|
||||
default:
|
||||
d.Set(a)
|
||||
f.data[i] = a
|
||||
}
|
||||
return next
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user