compiler: support shadowing via Block statements
This commit is contained in:
parent
40bacc6775
commit
26cfae7c9a
2 changed files with 11 additions and 0 deletions
|
@ -890,6 +890,16 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
|
||||
return nil
|
||||
|
||||
case *ast.BlockStmt:
|
||||
c.scope.vars.newScope()
|
||||
defer c.scope.vars.dropScope()
|
||||
|
||||
for i := range n.List {
|
||||
ast.Walk(c, n.List[i])
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *ast.ForStmt:
|
||||
c.scope.vars.newScope()
|
||||
defer c.scope.vars.dropScope()
|
||||
|
|
|
@ -81,4 +81,5 @@ func TestShadow(t *testing.T) {
|
|||
t.Run("For", runCase("for i := 0; i < 1; i++ {"))
|
||||
t.Run("Range", runCase("for range []int{1} {"))
|
||||
t.Run("Switch", runCase("switch true {\ncase false: x += 2\ncase true:"))
|
||||
t.Run("Block", runCase("{"))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue