fix: correct var creation from type convert (#172)

This commit is contained in:
Marc Vertes
2019-04-25 10:56:55 +02:00
committed by Ludovic Fernandez
parent eadeb86147
commit 0bbdd37e55
2 changed files with 15 additions and 3 deletions

12
_test/assign2.go Normal file
View File

@@ -0,0 +1,12 @@
package main
func main() {
r := uint32(2000000000)
r = hello(r)
println(r)
}
func hello(r uint32) uint32 { return r + 1 }
// Output:
// 2000000001

View File

@@ -170,14 +170,14 @@ func typeAssert2(n *Node) {
}
func convert(n *Node) {
i := n.findex
dest := genValue(n)
c := n.child[1]
typ := n.child[0].typ.TypeOf()
next := getExec(n.tnext)
if c.kind == BasicLit && c.val == nil { // convert nil to type
n.exec = func(f *Frame) Builtin {
f.data[i] = reflect.New(typ).Elem()
dest(f).Set(reflect.New(typ).Elem())
return next
}
return
@@ -191,7 +191,7 @@ func convert(n *Node) {
}
n.exec = func(f *Frame) Builtin {
f.data[i] = value(f).Convert(typ)
dest(f).Set(value(f).Convert(typ))
return next
}
}