v2: parser - use defer to make sure scope is closed for filter

pull/3859/head
joe-conigliaro 2020-02-27 17:00:24 +11:00
parent 06fc8a830b
commit cfbd8ab7e7
1 changed files with 3 additions and 13 deletions

View File

@ -868,12 +868,6 @@ fn (p mut Parser) index_expr(left ast.Expr) ast.IndexExpr {
} }
fn (p mut Parser) filter(typ table.Type) { fn (p mut Parser) filter(typ table.Type) {
/*
p.table.register_var(table.Var{
name: 'it'
typ: typ
})
*/
p.scope.register_var(ast.VarDecl{ p.scope.register_var(ast.VarDecl{
name: 'it' name: 'it'
typ: typ typ: typ
@ -886,6 +880,9 @@ fn (p mut Parser) dot_expr(left ast.Expr, left_type table.Type) ast.Expr {
if field_name == 'filter' { if field_name == 'filter' {
p.open_scope() p.open_scope()
p.filter(left_type) p.filter(left_type)
defer {
p.close_scope()
}
} }
// Method call // Method call
if p.tok.kind == .lpar { if p.tok.kind == .lpar {
@ -903,8 +900,6 @@ fn (p mut Parser) dot_expr(left ast.Expr, left_type table.Type) ast.Expr {
} }
mut node := ast.Expr{} mut node := ast.Expr{}
node = mcall_expr node = mcall_expr
// typ := p.add_unresolved('${left_type.typ.name}.${field_name}()', mcall_expr)
// typ := p.add_unresolved('${table.type_idx(left_type)}.${field_name}()', mcall_expr)
return node return node
} }
sel_expr := ast.SelectorExpr{ sel_expr := ast.SelectorExpr{
@ -912,13 +907,8 @@ fn (p mut Parser) dot_expr(left ast.Expr, left_type table.Type) ast.Expr {
field: field_name field: field_name
pos: p.tok.position() pos: p.tok.position()
} }
// typ := p.add_unresolved('${left_type.typ.name}.$field_name', sel_expr)
// typ := p.add_unresolved('${table.type_idx(left_type)}.$field_name', sel_expr)
mut node := ast.Expr{} mut node := ast.Expr{}
node = sel_expr node = sel_expr
if field_name == 'filter' {
p.close_scope()
}
return node return node
} }