diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index d87beb4beb..6410e4d724 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -640,3 +640,30 @@ enum BinaryOp { or_bool } */ + +[inline] +pub fn expr_is_blank_ident(expr Expr) bool { + match expr { + Ident { + return it.kind == .blank_ident + } + else { + return false + } + } +} + +[inline] +pub fn expr_is_call(expr Expr) bool { + return match expr { + CallExpr { + true + } + MethodCallExpr { + true + } + else { + false + } + } +} diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 561cb798ed..a8ddd7534d 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -154,13 +154,8 @@ pub fn (c mut Checker) infix_expr(infix_expr mut ast.InfixExpr) table.Type { } fn (c mut Checker) assign_expr(assign_expr mut ast.AssignExpr) { - match assign_expr.left { - ast.Ident { - if it.kind == .blank_ident { - return - } - } - else {} + if ast.expr_is_blank_ident(assign_expr.left) { + return } left_type := c.expr(assign_expr.left) c.expected_type = left_type diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index c525eb00a5..22ffab2b6d 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -401,7 +401,7 @@ fn (g mut Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) { ident_var_info := ident.var_info() styp := g.typ(ident_var_info.typ) if ident.kind == .blank_ident { - if is_call(val) { + if ast.expr_is_call(val) { g.expr(val) } else { @@ -562,8 +562,8 @@ fn (g mut Gen) expr(node ast.Expr) { g.write('/* as */') } ast.AssignExpr { - if is_blank_ident(it.left) { - if is_call(it.val) { + if ast.expr_is_blank_ident(it.left) { + if ast.expr_is_call(it.val) { g.expr(it.val) } else { @@ -1335,33 +1335,6 @@ fn (g mut Gen) ref_or_deref_arg(arg ast.CallArg) { } } -[inline] -fn is_blank_ident(expr ast.Expr) bool { - match expr { - ast.Ident { - return it.kind == .blank_ident - } - else { - return false - } - } -} - -[inline] -fn is_call(expr ast.Expr) bool { - return match expr { - ast.CallExpr { - true - } - ast.MethodCallExpr { - true - } - else { - false - } - } -} - fn verror(s string) { println('cgen error: $s') // exit(1) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index e2dfa368fd..6cf6ddce95 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -406,7 +406,7 @@ pub fn (p mut Parser) stmt() ast.Stmt { } } -// TODO: merge wtih AssignStmt & VarDecl +// TODO: is it possible to merge with AssignStmt? pub fn (p mut Parser) assign_expr(left ast.Expr) ast.AssignExpr { op := p.tok.kind p.next()