fix: correct wireChild() in case of interleaving of var and func declarations (#65)
This commit is contained in:
committed by
Ludovic Fernandez
parent
49c8c905d2
commit
83bc9c5f05
26
_test/var6.go
Normal file
26
_test/var6.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Foo struct {
|
||||
A string
|
||||
}
|
||||
|
||||
var f = Foo{"world"} // <-- the root cause
|
||||
|
||||
func Hello() {
|
||||
fmt.Println("in")
|
||||
}
|
||||
|
||||
var name = "v1" // <-- the root cause
|
||||
|
||||
func main() {
|
||||
Hello()
|
||||
fmt.Println("Hello", f.A, name)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// in
|
||||
// Hello world v1
|
||||
@@ -1035,7 +1035,12 @@ func wireChild(n *Node) {
|
||||
|
||||
// Chain sequential operations inside a block (next is right sibling)
|
||||
for i := 1; i < len(n.child); i++ {
|
||||
n.child[i-1].tnext = n.child[i].start
|
||||
switch n.child[i].kind {
|
||||
case FuncDecl:
|
||||
n.child[i-1].tnext = n.child[i]
|
||||
default:
|
||||
n.child[i-1].tnext = n.child[i].start
|
||||
}
|
||||
}
|
||||
|
||||
// Chain subtree next to self
|
||||
|
||||
@@ -6469,6 +6469,43 @@ func main() {
|
||||
// a: 64 int64
|
||||
}
|
||||
|
||||
func Example_var6() {
|
||||
src := `
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Foo struct {
|
||||
A string
|
||||
}
|
||||
|
||||
var f = Foo{"world"} // <-- the root cause
|
||||
|
||||
func Hello() {
|
||||
fmt.Println("in")
|
||||
}
|
||||
|
||||
var name = "v1" // <-- the root cause
|
||||
|
||||
func main() {
|
||||
Hello()
|
||||
fmt.Println("Hello", f.A, name)
|
||||
}
|
||||
`
|
||||
i := interp.New(interp.Opt{Entry: "main"})
|
||||
i.Use(stdlib.Value, stdlib.Type)
|
||||
_, err := i.Eval(src)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// in
|
||||
// Hello world v1
|
||||
}
|
||||
|
||||
func Example_variadic() {
|
||||
src := `
|
||||
package main
|
||||
|
||||
@@ -74,6 +74,7 @@ func (interp *Interpreter) run(n *Node, cf *Frame) {
|
||||
} else {
|
||||
f = &Frame{anc: cf, data: make([]reflect.Value, n.flen)}
|
||||
}
|
||||
|
||||
for i, t := range n.types {
|
||||
// FIXME: nil types are forbidden and should be detected at compile time (CFG)
|
||||
if t != nil && i < len(f.data) && !f.data[i].IsValid() {
|
||||
@@ -606,7 +607,7 @@ func callBin(n *Node) {
|
||||
}
|
||||
//log.Println(n.index, "callbin", value(f).Type(), in)
|
||||
r := value(f).Call(in)
|
||||
//log.Println(n.index, "callBin, res:", v, fsize, n.findex)
|
||||
//log.Println(n.index, "callBin, res:", r, fsize, n.findex, len(r), len(f.data))
|
||||
for i := 0; i < fsize; i++ {
|
||||
f.data[n.findex+i] = r[i]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user