File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -641,7 +641,17 @@ def warn(*messages, uplevel: undefined)
641
641
uplevel = Primitive . rb_to_int ( uplevel )
642
642
raise ArgumentError , "negative level (#{ uplevel } )" unless uplevel >= 0
643
643
644
- caller , = Kernel . caller_locations ( uplevel + 1 , 1 )
644
+ uplevel += 1 # skip Kernel#warn itself
645
+ initial , = Kernel . caller_locations ( uplevel , 1 )
646
+ caller = initial
647
+ # MRI would reuse the file:line of the user code caller for methods defined in C.
648
+ # Similarly, we skip <internal:* calls, notably to skip Kernel#require calls.
649
+ while caller and caller . path . start_with? ( '<internal:' )
650
+ uplevel += 1
651
+ caller , = Kernel . caller_locations ( uplevel , 1 )
652
+ end
653
+ caller = initial unless caller
654
+
645
655
if caller
646
656
"#{ caller . path } :#{ caller . lineno } : warning: "
647
657
else
You can’t perform that action at this time.
0 commit comments