diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index d0b56201cb..eba4183fc3 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -731,6 +731,7 @@ pub struct OrExpr { pub: stmts []Stmt kind OrKind + pos token.Position } pub struct Assoc { diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 8f58106028..1ff22ca7de 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2973,7 +2973,12 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type table. } } else if or_block.kind == .propagate { if g.file.mod.name == 'main' && g.cur_fn.name == 'main' { - g.writeln('\tv_panic(${cvar_name}.v_error);') + if g.pref.is_debug { + paline, pafile, pamod, pafn := g.panic_debug_info(or_block.pos) + g.writeln('panic_debug($paline, tos3("$pafile"), tos3("$pamod"), tos3("$pafn"), ${cvar_name}.v_error );') + }else{ + g.writeln('\tv_panic(${cvar_name}.v_error);') + } } else { g.writeln('\treturn $cvar_name;') } @@ -3982,3 +3987,18 @@ fn (g &Gen) interface_call(typ, interface_type table.Type) { g.write('&') } } + +fn (mut g Gen) panic_debug_info(pos token.Position) (int, string, string, string) { + paline := pos.line_nr + 1 + pafile := g.fn_decl.file.replace('\\', '/') + pafn := g.fn_decl.name.after('.') + mut pamod := g.fn_decl.name.all_before_last('.') + if pamod == pafn { + pamod = if g.fn_decl.is_builtin { + 'builtin' + } else { + 'main' + } + } + return paline, pafile, pamod, pafn +} diff --git a/vlib/v/gen/fn.v b/vlib/v/gen/fn.v index 13879af772..a80e34d059 100644 --- a/vlib/v/gen/fn.v +++ b/vlib/v/gen/fn.v @@ -533,17 +533,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) { g.write('))') } } else if g.pref.is_debug && node.name == 'panic' { - paline := node.pos.line_nr + 1 - pafile := g.fn_decl.file.replace('\\', '/') - pafn := g.fn_decl.name.after('.') - mut pamod := g.fn_decl.name.all_before_last('.') - if pamod == pafn { - pamod = if g.fn_decl.is_builtin { - 'builtin' - } else { - 'main' - } - } + paline, pafile, pamod, pafn := g.panic_debug_info(node.pos) g.write('panic_debug($paline, tos3("$pafile"), tos3("$pamod"), tos3("$pafn"), ') g.call_args(node.args, node.expected_arg_types) g.write(')') diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 85709bec03..0190df883e 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -80,6 +80,7 @@ pub fn (mut p Parser) call_expr(language table.Language, mod string) ast.CallExp or_block: ast.OrExpr{ stmts: or_stmts kind: or_kind + pos: pos } generic_type: generic_type } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 1dbe12584f..6b9262d717 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1026,6 +1026,7 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr { or_block: ast.OrExpr{ stmts: or_stmts kind: or_kind + pos: pos } } if is_filter {