@@ -4638,7 +4638,7 @@ impl Compiler {
46384638 self . emit_load_const ( ConstantData :: Str { value : name. into ( ) } ) ;
46394639
46404640 if let Some ( arguments) = arguments {
4641- self . codegen_call_helper ( 2 , arguments) ?;
4641+ self . codegen_call_helper ( 2 , arguments, self . current_source_range ) ?;
46424642 } else {
46434643 emit ! ( self , Instruction :: Call { nargs: 2 } ) ;
46444644 }
@@ -7079,6 +7079,10 @@ impl Compiler {
70797079 }
70807080
70817081 fn compile_call ( & mut self , func : & ast:: Expr , args : & ast:: Arguments ) -> CompileResult < ( ) > {
7082+ // Save the call expression's source range so CALL instructions use the
7083+ // call start line, not the last argument's line.
7084+ let call_range = self . current_source_range ;
7085+
70827086 // Method call: obj → LOAD_ATTR_METHOD → [method, self_or_null] → args → CALL
70837087 // Regular call: func → PUSH_NULL → args → CALL
70847088 if let ast:: Expr :: Attribute ( ast:: ExprAttribute { value, attr, .. } ) = & func {
@@ -7096,21 +7100,21 @@ impl Compiler {
70967100 self . emit_load_zero_super_method ( idx) ;
70977101 }
70987102 }
7099- self . codegen_call_helper ( 0 , args) ?;
7103+ self . codegen_call_helper ( 0 , args, call_range ) ?;
71007104 } else {
71017105 // Normal method call: compile object, then LOAD_ATTR with method flag
71027106 // LOAD_ATTR(method=1) pushes [method, self_or_null] on stack
71037107 self . compile_expression ( value) ?;
71047108 let idx = self . name ( attr. as_str ( ) ) ;
71057109 self . emit_load_attr_method ( idx) ;
7106- self . codegen_call_helper ( 0 , args) ?;
7110+ self . codegen_call_helper ( 0 , args, call_range ) ?;
71077111 }
71087112 } else {
71097113 // Regular call: push func, then NULL for self_or_null slot
71107114 // Stack layout: [func, NULL, args...] - same as method call [func, self, args...]
71117115 self . compile_expression ( func) ?;
71127116 emit ! ( self , Instruction :: PushNull ) ;
7113- self . codegen_call_helper ( 0 , args) ?;
7117+ self . codegen_call_helper ( 0 , args, call_range ) ?;
71147118 }
71157119 Ok ( ( ) )
71167120 }
@@ -7152,10 +7156,13 @@ impl Compiler {
71527156 }
71537157
71547158 /// Compile call arguments and emit the appropriate CALL instruction.
7159+ /// `call_range` is the source range of the call expression, used to set
7160+ /// the correct line number on the CALL instruction.
71557161 fn codegen_call_helper (
71567162 & mut self ,
71577163 additional_positional : u32 ,
71587164 arguments : & ast:: Arguments ,
7165+ call_range : TextRange ,
71597166 ) -> CompileResult < ( ) > {
71607167 let nelts = arguments. args . len ( ) ;
71617168 let nkwelts = arguments. keywords . len ( ) ;
@@ -7186,13 +7193,16 @@ impl Compiler {
71867193 self . compile_expression ( & keyword. value ) ?;
71877194 }
71887195
7196+ // Restore call expression range for kwnames and CALL_KW
7197+ self . set_source_range ( call_range) ;
71897198 self . emit_load_const ( ConstantData :: Tuple {
71907199 elements : kwarg_names,
71917200 } ) ;
71927201
71937202 let nargs = additional_positional + nelts. to_u32 ( ) + nkwelts. to_u32 ( ) ;
71947203 emit ! ( self , Instruction :: CallKw { nargs } ) ;
71957204 } else {
7205+ self . set_source_range ( call_range) ;
71967206 let nargs = additional_positional + nelts. to_u32 ( ) ;
71977207 emit ! ( self , Instruction :: Call { nargs } ) ;
71987208 }
@@ -7284,6 +7294,7 @@ impl Compiler {
72847294 emit ! ( self , Instruction :: PushNull ) ;
72857295 }
72867296
7297+ self . set_source_range ( call_range) ;
72877298 emit ! ( self , Instruction :: CallFunctionEx ) ;
72887299 }
72897300
0 commit comments