Fix panic for empty statement block
This commit is contained in:
@@ -2,7 +2,10 @@ package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var samples = []int{}
|
||||
var (
|
||||
samples = []int{}
|
||||
b = 1
|
||||
)
|
||||
|
||||
func main() {
|
||||
samples = append(samples, 1)
|
||||
|
||||
11
_test/fun4.go
Normal file
11
_test/fun4.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
func f() {}
|
||||
|
||||
func main() {
|
||||
f()
|
||||
println("ok")
|
||||
}
|
||||
|
||||
// Output:
|
||||
// ok
|
||||
@@ -9,3 +9,8 @@ func Foo() {
|
||||
func F1() {
|
||||
fmt.Println("SomeString:", SomeString)
|
||||
}
|
||||
|
||||
//func F2() {
|
||||
//var buf [SomeInt]byte
|
||||
//fmt.Println("buf:", buf)
|
||||
//}
|
||||
|
||||
@@ -331,7 +331,9 @@ func (interp *Interpreter) Cfg(root *Node) []*Node {
|
||||
|
||||
case BlockStmt:
|
||||
wireChild(n)
|
||||
n.findex = n.child[len(n.child)-1].findex
|
||||
if len(n.child) > 0 {
|
||||
n.findex = n.child[len(n.child)-1].findex
|
||||
}
|
||||
scope = scope.pop()
|
||||
|
||||
case ConstDecl:
|
||||
@@ -450,7 +452,7 @@ func (interp *Interpreter) Cfg(root *Node) []*Node {
|
||||
n.fsize = 0
|
||||
}
|
||||
} else {
|
||||
log.Println(n.index, "resolve method")
|
||||
log.Println(n.index, "unresolve call")
|
||||
// method must be resolved here due to declaration after use
|
||||
}
|
||||
n.child[0].findex = -1 // To force reading value from node instead of frame (methods)
|
||||
|
||||
@@ -292,7 +292,10 @@ package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var samples = []int{}
|
||||
var (
|
||||
samples = []int{}
|
||||
b = 1
|
||||
)
|
||||
|
||||
func main() {
|
||||
samples = append(samples, 1)
|
||||
@@ -916,6 +919,24 @@ func main() {
|
||||
// 18
|
||||
}
|
||||
|
||||
func Example_fun4() {
|
||||
src := `
|
||||
package main
|
||||
|
||||
func f() {}
|
||||
|
||||
func main() {
|
||||
f()
|
||||
println("ok")
|
||||
}
|
||||
`
|
||||
i := NewInterpreter(Opt{Entry: "main"})
|
||||
i.Eval(src)
|
||||
|
||||
// Output:
|
||||
// ok
|
||||
}
|
||||
|
||||
func Example_goroutine() {
|
||||
src := `
|
||||
package main
|
||||
|
||||
Reference in New Issue
Block a user