Skip to content

Commit

Permalink
handle labeled stmt
Browse files Browse the repository at this point in the history
Signed-off-by: Iskander Sharipov <[email protected]>
  • Loading branch information
quasilyte committed Jan 25, 2019
1 parent 634bb9b commit cfe2470
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ func (n *normalizer) normalizeExprList(xs []ast.Expr) []ast.Expr {

func (n *normalizer) normalizeStmt(x ast.Stmt) ast.Stmt {
switch x := x.(type) {
case *ast.LabeledStmt:
return n.normalizeLabeledStmt(x)
case *ast.ExprStmt:
return n.normalizeExprStmt(x)
case *ast.AssignStmt:
Expand Down Expand Up @@ -405,7 +407,12 @@ func (n *normalizer) normalizeValSwap(b *ast.BlockStmt) {
}
}

func (n *normalizer) normalizeExprStmt(stmt *ast.ExprStmt) ast.Stmt {
func (n *normalizer) normalizeLabeledStmt(stmt *ast.LabeledStmt) *ast.LabeledStmt {
stmt.Stmt = n.normalizeStmt(stmt.Stmt)
return stmt
}

func (n *normalizer) normalizeExprStmt(stmt *ast.ExprStmt) *ast.ExprStmt {
stmt.X = n.normalizeExpr(stmt.X)
return stmt
}
Expand Down
12 changes: 12 additions & 0 deletions testdata/normalize_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ func exprStmtTest() {
}
}

func labeledStmtTest() {
_, _ = func() int {
goto L
L:
return (0)
}, func() int {
goto L
L:
return 0
}
}

func combinedTest() {
var x int

Expand Down

0 comments on commit cfe2470

Please sign in to comment.