}
}
-func (p *parser) shortVarDecl(decl *ast.AssignStmt, list []ast.Expr) {
+func (p *parser) shortVarDecl(decl *ast.AssignStmt) {
// Go spec: A short variable declaration may redeclare variables
// provided they were originally declared in the same block with
// the same type, and at least one of the non-blank variables is new.
n := 0 // number of new variables
- for _, x := range list {
+ for _, x := range decl.Lhs {
if ident, isIdent := x.(*ast.Ident); isIdent {
assert(ident.Obj == nil, "identifier already declared or resolved")
obj := ast.NewObj(ast.Var, ident.Name)
}
}
if n == 0 && p.mode&DeclarationErrors != 0 {
- p.error(list[0].Pos(), "no new variables on left side of :=")
+ p.error(decl.Lhs[0].Pos(), "no new variables on left side of :=")
}
}
}
as := &ast.AssignStmt{Lhs: x, TokPos: pos, Tok: tok, Rhs: y}
if tok == token.DEFINE {
- p.shortVarDecl(as, x)
+ p.shortVarDecl(as)
}
return as, isRange
}
rhs := p.parseRhs()
as := &ast.AssignStmt{Lhs: lhs, TokPos: pos, Tok: tok, Rhs: []ast.Expr{rhs}}
if tok == token.DEFINE {
- p.shortVarDecl(as, lhs)
+ p.shortVarDecl(as)
}
comm = as
} else {