fix: handle empty case body (#244)

This commit is contained in:
Marc Vertes
2019-07-11 14:02:59 +02:00
committed by Ludovic Fernandez
parent 7d5ed8a713
commit f082ca73f0
3 changed files with 33 additions and 2 deletions

11
_test/if1.go Normal file
View File

@@ -0,0 +1,11 @@
package main
func main() {
i := 1
if i > 0 {
}
println("bye")
}
// Output:
// bye

16
_test/switch20.go Normal file
View File

@@ -0,0 +1,16 @@
package main
func main() {
i := 1
switch i {
case 1:
// nothing to do
default:
println("not run")
}
println("bye")
}
// Output:
// bye

View File

@@ -750,9 +750,13 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) {
case caseBody:
wireChild(n)
if typeSwichAssign(n) && len(n.child) > 1 {
switch {
case typeSwichAssign(n) && len(n.child) > 1:
n.start = n.child[1].start
} else {
case len(n.child) == 0:
// empty case body: jump to switch node (exit node)
n.start = n.anc.anc.anc
default:
n.start = n.child[0].start
}