@@ -5051,6 +5051,16 @@ fn tryExpr(
5051
5051
5052
5052
if (parent_gz .in_defer ) return astgen .failNode (node , "'try' not allowed inside defer expression" , .{});
5053
5053
5054
+ // Ensure debug line/column information is emitted for this try expression.
5055
+ // Then we will save the line/column so that we can emit another one that goes
5056
+ // "backwards" because we want to evaluate the operand, but then put the debug
5057
+ // info back at the try keyword for error return tracing.
5058
+ if (! parent_gz .force_comptime ) {
5059
+ try emitDbgNode (parent_gz , node );
5060
+ }
5061
+ const try_line = astgen .source_line - parent_gz .decl_line ;
5062
+ const try_column = astgen .source_column ;
5063
+
5054
5064
const operand_rl : ResultLoc = switch (rl ) {
5055
5065
.ref = > .ref ,
5056
5066
else = > .none ,
@@ -5080,6 +5090,7 @@ fn tryExpr(
5080
5090
};
5081
5091
const err_code = try else_scope .addUnNode (err_tag , operand , node );
5082
5092
try genDefers (& else_scope , & fn_block .base , scope , .{ .both = err_code });
5093
+ try emitDbgStmt (& else_scope , try_line , try_column );
5083
5094
_ = try else_scope .addUnNode (.ret_node , err_code , node );
5084
5095
5085
5096
try else_scope .setTryBody (try_inst , operand );
@@ -6614,13 +6625,13 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
6614
6625
const defer_counts = countDefers (astgen , defer_outer , scope );
6615
6626
if (! defer_counts .need_err_code ) {
6616
6627
try genDefers (gz , defer_outer , scope , .both_sans_err );
6617
- try emitRetDbgStmt (gz , ret_line , ret_column );
6628
+ try emitDbgStmt (gz , ret_line , ret_column );
6618
6629
_ = try gz .addStrTok (.ret_err_value , err_name_str_index , ident_token );
6619
6630
return Zir .Inst .Ref .unreachable_value ;
6620
6631
}
6621
6632
const err_code = try gz .addStrTok (.ret_err_value_code , err_name_str_index , ident_token );
6622
6633
try genDefers (gz , defer_outer , scope , .{ .both = err_code });
6623
- try emitRetDbgStmt (gz , ret_line , ret_column );
6634
+ try emitDbgStmt (gz , ret_line , ret_column );
6624
6635
_ = try gz .addUnNode (.ret_node , err_code , node );
6625
6636
return Zir .Inst .Ref .unreachable_value ;
6626
6637
}
@@ -6639,15 +6650,15 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
6639
6650
.never = > {
6640
6651
// Returning a value that cannot be an error; skip error defers.
6641
6652
try genDefers (gz , defer_outer , scope , .normal_only );
6642
- try emitRetDbgStmt (gz , ret_line , ret_column );
6653
+ try emitDbgStmt (gz , ret_line , ret_column );
6643
6654
try gz .addRet (rl , operand , node );
6644
6655
return Zir .Inst .Ref .unreachable_value ;
6645
6656
},
6646
6657
.always = > {
6647
6658
// Value is always an error. Emit both error defers and regular defers.
6648
6659
const err_code = if (rl == .ptr ) try gz .addUnNode (.load , rl .ptr , node ) else operand ;
6649
6660
try genDefers (gz , defer_outer , scope , .{ .both = err_code });
6650
- try emitRetDbgStmt (gz , ret_line , ret_column );
6661
+ try emitDbgStmt (gz , ret_line , ret_column );
6651
6662
try gz .addRet (rl , operand , node );
6652
6663
return Zir .Inst .Ref .unreachable_value ;
6653
6664
},
@@ -6656,7 +6667,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
6656
6667
if (! defer_counts .have_err ) {
6657
6668
// Only regular defers; no branch needed.
6658
6669
try genDefers (gz , defer_outer , scope , .normal_only );
6659
- try emitRetDbgStmt (gz , ret_line , ret_column );
6670
+ try emitDbgStmt (gz , ret_line , ret_column );
6660
6671
try gz .addRet (rl , operand , node );
6661
6672
return Zir .Inst .Ref .unreachable_value ;
6662
6673
}
@@ -6670,7 +6681,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
6670
6681
defer then_scope .unstack ();
6671
6682
6672
6683
try genDefers (& then_scope , defer_outer , scope , .normal_only );
6673
- try emitRetDbgStmt ( gz , ret_line , ret_column );
6684
+ try emitDbgStmt ( & then_scope , ret_line , ret_column );
6674
6685
try then_scope .addRet (rl , operand , node );
6675
6686
6676
6687
var else_scope = gz .makeSubBlock (scope );
@@ -6680,7 +6691,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
6680
6691
.both = try else_scope .addUnNode (.err_union_code , result , node ),
6681
6692
};
6682
6693
try genDefers (& else_scope , defer_outer , scope , which_ones );
6683
- try emitRetDbgStmt ( gz , ret_line , ret_column );
6694
+ try emitDbgStmt ( & else_scope , ret_line , ret_column );
6684
6695
try else_scope .addRet (rl , operand , node );
6685
6696
6686
6697
try setCondBrPayload (condbr , is_non_err , & then_scope , 0 , & else_scope , 0 );
@@ -11698,7 +11709,7 @@ fn countBodyLenAfterFixups(astgen: *AstGen, body: []const Zir.Inst.Index) u32 {
11698
11709
return @intCast (u32 , count );
11699
11710
}
11700
11711
11701
- fn emitRetDbgStmt (gz : * GenZir , line : u32 , column : u32 ) ! void {
11712
+ fn emitDbgStmt (gz : * GenZir , line : u32 , column : u32 ) ! void {
11702
11713
if (gz .force_comptime ) return ;
11703
11714
11704
11715
_ = try gz .add (.{ .tag = .dbg_stmt , .data = .{
0 commit comments