fix: correct new() when using in indirect assign (#202)

This commit is contained in:
Marc Vertes
2019-05-31 19:49:40 +02:00
committed by Ludovic Fernandez
parent 548c57efc3
commit ad009959af
2 changed files with 15 additions and 2 deletions

13
_test/new1.go Normal file
View File

@@ -0,0 +1,13 @@
package main
import "fmt"
func main() {
a := [1]*int{}
a[0] = new(int)
*a[0] = 2
fmt.Println(*a[0])
}
// Output:
// 2

View File

@@ -1769,12 +1769,12 @@ func _len(n *Node) {
}
func _new(n *Node) {
i := n.findex
dest := genValue(n)
next := getExec(n.tnext)
typ := n.child[1].typ.TypeOf()
n.exec = func(f *Frame) Builtin {
f.data[i] = reflect.New(typ)
dest(f).Set(reflect.New(typ))
return next
}
}