diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 08cb84755f..35836502d6 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -2146,31 +2146,11 @@ pub fn (t &Table) is_comptime_type(x Type, y ComptimeType) bool { pub fn (t &Table) dependent_names_in_expr(expr Expr) []string { mut names := []string{} match expr { - Ident { - if expr.kind in [.global, .constant] { - names << util.no_dots(expr.name) - } - } ArrayInit { for elem_expr in expr.exprs { names << t.dependent_names_in_expr(elem_expr) } } - StructInit { - for field in expr.fields { - names << t.dependent_names_in_expr(field.expr) - } - } - InfixExpr { - names << t.dependent_names_in_expr(expr.left) - names << t.dependent_names_in_expr(expr.right) - } - PostfixExpr { - names << t.dependent_names_in_expr(expr.expr) - } - PrefixExpr { - names << t.dependent_names_in_expr(expr.right) - } CallExpr { for arg in expr.args { names << t.dependent_names_in_expr(arg.expr) @@ -2179,6 +2159,15 @@ pub fn (t &Table) dependent_names_in_expr(expr Expr) []string { names << func.dep_names } } + CastExpr { + names << t.dependent_names_in_expr(expr.expr) + names << t.dependent_names_in_expr(expr.arg) + } + Ident { + if expr.kind in [.global, .constant] { + names << util.no_dots(expr.name) + } + } IfExpr { for branch in expr.branches { names << t.dependent_names_in_expr(branch.cond) @@ -2187,6 +2176,15 @@ pub fn (t &Table) dependent_names_in_expr(expr Expr) []string { } } } + InfixExpr { + names << t.dependent_names_in_expr(expr.left) + names << t.dependent_names_in_expr(expr.right) + } + MapInit { + for val in expr.vals { + names << t.dependent_names_in_expr(val) + } + } MatchExpr { names << t.dependent_names_in_expr(expr.cond) for branch in expr.branches { @@ -2195,6 +2193,20 @@ pub fn (t &Table) dependent_names_in_expr(expr Expr) []string { } } } + ParExpr { + names << t.dependent_names_in_expr(expr.expr) + } + PostfixExpr { + names << t.dependent_names_in_expr(expr.expr) + } + PrefixExpr { + names << t.dependent_names_in_expr(expr.right) + } + StructInit { + for field in expr.fields { + names << t.dependent_names_in_expr(field.expr) + } + } else {} } return names @@ -2220,6 +2232,19 @@ pub fn (t &Table) dependent_names_in_stmt(stmt Stmt) []string { names << t.dependent_names_in_stmt(stmt_) } } + ForStmt { + for stmt_ in stmt.stmts { + names << t.dependent_names_in_stmt(stmt_) + } + } + ForCStmt { + names << t.dependent_names_in_stmt(stmt.init) + names << t.dependent_names_in_expr(stmt.cond) + names << t.dependent_names_in_stmt(stmt.inc) + for stmt_ in stmt.stmts { + names << t.dependent_names_in_stmt(stmt_) + } + } Return { for expr in stmt.exprs { names << t.dependent_names_in_expr(expr) diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index d26b760f87..321ed14088 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -335,7 +335,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { } node.source_file = c.file - if c.table.known_fn(node.name) { + if c.table.known_fn(node.name) && node.name != 'main.main' { mut dep_names := []string{} for stmt in node.stmts { dep_names << c.table.dependent_names_in_stmt(stmt) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 5763725806..31c9bc013b 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -4595,7 +4595,7 @@ fn (mut g Gen) const_decl_init_later(mod string, name string, expr ast.Expr, typ g.global_const_defs[util.no_dots(name)] = GlobalConstDef{ mod: mod def: '$styp $cname; // inited later' - init: init.str() + init: init.str().trim_right('\n') dep_names: g.table.dependent_names_in_expr(expr) } if g.is_autofree {