Fix setting composite litterals in nested scopes
This commit is contained in:
@@ -231,6 +231,7 @@ func (interp *Interpreter) Cfg(root *Node) []*Node {
|
||||
} else if n.child[1].action == CompositeLit {
|
||||
n.gen = nop
|
||||
n.child[1].findex = n.child[0].findex
|
||||
n.child[1].level = level
|
||||
}
|
||||
n.typ = n.child[0].typ
|
||||
if sym != nil {
|
||||
@@ -698,7 +699,7 @@ func (interp *Interpreter) Cfg(root *Node) []*Node {
|
||||
} else if isNewDefine(n) {
|
||||
// Create a new symbol in current scope, type to be set by parent node
|
||||
// Note that global symbol should already be defined (gta)
|
||||
if _, _, ok := scope.lookup(n.ident); !ok && !scope.global {
|
||||
if _, _, ok := scope.lookup(n.ident); !ok || !scope.global {
|
||||
n.findex = scope.inc(interp)
|
||||
scope.sym[n.ident] = &Symbol{index: scope.size, kind: Var, global: scope.global}
|
||||
n.sym = scope.sym[n.ident]
|
||||
|
||||
@@ -1223,7 +1223,7 @@ func _return(n *Node) {
|
||||
}
|
||||
|
||||
func arrayLit(n *Node) {
|
||||
ind := n.findex
|
||||
value := valueGenerator(n, n.findex)
|
||||
next := getExec(n.tnext)
|
||||
child := n.child[1:]
|
||||
zero := n.typ.zero
|
||||
@@ -1239,7 +1239,7 @@ func arrayLit(n *Node) {
|
||||
for i, v := range values {
|
||||
a.Index(i).Set(v(f))
|
||||
}
|
||||
f.data[ind] = a
|
||||
value(f).Set(a)
|
||||
return next
|
||||
}
|
||||
} else {
|
||||
@@ -1249,14 +1249,14 @@ func arrayLit(n *Node) {
|
||||
for _, v := range values {
|
||||
a = reflect.Append(a, v(f))
|
||||
}
|
||||
f.data[ind] = a
|
||||
value(f).Set(a)
|
||||
return next
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mapLit(n *Node) {
|
||||
ind := n.findex
|
||||
value := valueGenerator(n, n.findex)
|
||||
next := getExec(n.tnext)
|
||||
child := n.child[1:]
|
||||
typ := n.typ.TypeOf()
|
||||
@@ -1272,14 +1272,14 @@ func mapLit(n *Node) {
|
||||
for i, k := range keys {
|
||||
m.SetMapIndex(k(f), values[i](f))
|
||||
}
|
||||
f.data[ind] = m
|
||||
value(f).Set(m)
|
||||
return next
|
||||
}
|
||||
}
|
||||
|
||||
// compositeLit creates a struct object
|
||||
func compositeLit(n *Node) {
|
||||
ind := n.findex
|
||||
value := valueGenerator(n, n.findex)
|
||||
next := getExec(n.tnext)
|
||||
child := n.child[1:]
|
||||
values := make([]func(*Frame) reflect.Value, len(child))
|
||||
@@ -1292,14 +1292,14 @@ func compositeLit(n *Node) {
|
||||
for i, v := range values {
|
||||
a.Field(i).Set(v(f))
|
||||
}
|
||||
f.data[ind] = a
|
||||
value(f).Set(a)
|
||||
return next
|
||||
}
|
||||
}
|
||||
|
||||
// compositeSparse creates a struct Object, filling fields from sparse key-values
|
||||
func compositeSparse(n *Node) {
|
||||
ind := n.findex
|
||||
value := valueGenerator(n, n.findex)
|
||||
next := getExec(n.tnext)
|
||||
child := n.child[1:]
|
||||
values := make(map[int]func(*Frame) reflect.Value)
|
||||
@@ -1312,7 +1312,7 @@ func compositeSparse(n *Node) {
|
||||
for i, v := range values {
|
||||
a.Field(i).Set(v(f))
|
||||
}
|
||||
f.data[ind] = a
|
||||
value(f).Set(a)
|
||||
return next
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user