Fix handling map boolean values
This commit is contained in:
13
_test/bool3.go
Normal file
13
_test/bool3.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
m := map[int]bool{0: false, 1: true}
|
||||
if m[0] {
|
||||
println(0)
|
||||
} else {
|
||||
println(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 1
|
||||
@@ -613,6 +613,26 @@ func main() {
|
||||
// nok
|
||||
}
|
||||
|
||||
func Example_bool3() {
|
||||
src := `
|
||||
package main
|
||||
|
||||
func main() {
|
||||
m := map[int]bool{0: false, 1: true}
|
||||
if m[0] {
|
||||
println(0)
|
||||
} else {
|
||||
println(1)
|
||||
}
|
||||
}
|
||||
`
|
||||
i := NewInterpreter(Opt{Entry: "main"}, "bool3.go")
|
||||
i.Eval(src)
|
||||
|
||||
// Output:
|
||||
// 1
|
||||
}
|
||||
|
||||
func Example_chan0() {
|
||||
src := `
|
||||
package main
|
||||
|
||||
@@ -565,14 +565,24 @@ func getIndexArray(n *Node) {
|
||||
|
||||
// getIndexMap retrieves map value from index
|
||||
func getIndexMap(n *Node) {
|
||||
i := n.findex
|
||||
value0 := genValue(n.child[0]) // map
|
||||
value1 := genValue(n.child[1]) // index
|
||||
next := getExec(n.tnext)
|
||||
tnext := getExec(n.tnext)
|
||||
|
||||
n.exec = func(f *Frame) Builtin {
|
||||
f.data[i] = value0(f).MapIndex(value1(f))
|
||||
return next
|
||||
if n.fnext != nil {
|
||||
fnext := getExec(n.fnext)
|
||||
n.exec = func(f *Frame) Builtin {
|
||||
if value0(f).MapIndex(value1(f)).Bool() {
|
||||
return tnext
|
||||
}
|
||||
return fnext
|
||||
}
|
||||
} else {
|
||||
i := n.findex
|
||||
n.exec = func(f *Frame) Builtin {
|
||||
f.data[i] = value0(f).MapIndex(value1(f))
|
||||
return tnext
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user