Skip to content

Commit cbd8095

Browse files
committed
handle deleting from map during iteration correctly (fixes #85)
1 parent 7f59447 commit cbd8095

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/statements.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package compiler
22

33
import (
4-
"code.google.com/p/go.tools/go/types"
54
"fmt"
65
"go/ast"
76
"go/token"
87
"strings"
8+
9+
"code.google.com/p/go.tools/go/types"
910
)
1011

1112
type This struct {
@@ -157,6 +158,10 @@ func (c *funcContext) translateStmt(stmt ast.Stmt, label string) {
157158
c.translateLoopingStmt(iVar+" < "+keysVar+".length", s.Body, func() {
158159
entryVar := c.newVariable("_entry")
159160
c.Printf("%s = %s[%s[%s]];", entryVar, refVar, keysVar, iVar)
161+
c.translateStmt(&ast.IfStmt{
162+
Cond: c.newIdent(entryVar+" === undefined", types.Typ[types.Bool]),
163+
Body: &ast.BlockStmt{List: []ast.Stmt{&ast.BranchStmt{Tok: token.CONTINUE}}},
164+
}, "")
160165
if !isBlank(s.Key) {
161166
c.Printf("%s", c.translateAssign(s.Key, entryVar+".k", t.Key(), s.Tok == token.DEFINE))
162167
}

0 commit comments

Comments
 (0)