Skip to content

Commit

Permalink
Fix failing test: do not replace nested breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-kamphaus-jemmic committed Jun 4, 2018
1 parent 9fec47f commit 76f7566
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions transpiler/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,21 @@ func handleLabelCases(cases []goast.Stmt, p *program.Program) (newCases []goast.
})
}
}
if _, ok := node.(*goast.ForStmt); ok {
return false
}
if _, ok := node.(*goast.RangeStmt); ok {
return false
}
if _, ok := node.(*goast.SwitchStmt); ok {
return false
}
if _, ok := node.(*goast.TypeSwitchStmt); ok {
return false
}
if _, ok := node.(*goast.SelectStmt); ok {
return false
}
return true
}
for i, x := range cases {
Expand All @@ -502,7 +517,7 @@ func handleLabelCases(cases []goast.Stmt, p *program.Program) (newCases []goast.
}

// Replace break's with goto swEndLabel
astutil.Apply(c, nil, funcTransformBreak)
astutil.Apply(c, funcTransformBreak, nil)
body := c.Body

// append caseLabel label followed by case body
Expand Down Expand Up @@ -548,7 +563,7 @@ func handleLabelCases(cases []goast.Stmt, p *program.Program) (newCases []goast.
}

// Replace break's with goto swEndLabel
astutil.Apply(c, nil, funcTransformBreak)
astutil.Apply(c, funcTransformBreak, nil)

// append label followed by label body
postStmts = append(postStmts, c)
Expand Down

0 comments on commit 76f7566

Please sign in to comment.