fix: handle empty case body (#244)
This commit is contained in:
committed by
Ludovic Fernandez
parent
7d5ed8a713
commit
f082ca73f0
11
_test/if1.go
Normal file
11
_test/if1.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
i := 1
|
||||
if i > 0 {
|
||||
}
|
||||
println("bye")
|
||||
}
|
||||
|
||||
// Output:
|
||||
// bye
|
||||
16
_test/switch20.go
Normal file
16
_test/switch20.go
Normal 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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user