Skip to content

Commit

Permalink
handle exprstmt
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 40f5bcb commit 634bb9b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 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.ExprStmt:
return n.normalizeExprStmt(x)
case *ast.AssignStmt:
return n.normalizeAssignStmt(x)
case *ast.BlockStmt:
Expand Down Expand Up @@ -403,6 +405,11 @@ func (n *normalizer) normalizeValSwap(b *ast.BlockStmt) {
}
}

func (n *normalizer) normalizeExprStmt(stmt *ast.ExprStmt) ast.Stmt {
stmt.X = n.normalizeExpr(stmt.X)
return stmt
}

func (n *normalizer) normalizeAssignStmt(assign *ast.AssignStmt) ast.Stmt {
for i, lhs := range assign.Lhs {
assign.Lhs[i] = n.normalizeExpr(lhs)
Expand Down
10 changes: 10 additions & 0 deletions testdata/normalize_stmt.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package normalize_stmt

func addInts(x, y int) int { return x + y }

func identityTest() {
var x int

Expand Down Expand Up @@ -260,6 +262,14 @@ func rangeLoopTest() {
}
}

func exprStmtTest() {
_, _ = func() {
addInts((1), 0+0+0)
}, func() {
addInts(1, 0)
}
}

func combinedTest() {
var x int

Expand Down

0 comments on commit 634bb9b

Please sign in to comment.