Project

General

Profile

Actions

Bug #21784

open

Proc#source_location start column seems strange for -> {}

Bug #21784: Proc#source_location start column seems strange for -> {}

Added by Eregon (Benoit Daloze) 1 day ago. Updated about 9 hours ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.0dev (2025-12-14T07:11:02Z master 711d14992e) +PRISM [x86_64-linux]
[ruby-core:124207]

Description

$ ruby -e 'p -> { a }.source_location' 
["-e", 1, 4, 1, 10]

So it considers the stabby lambda to be at:

p -> { a }.source_location
    ^^^^^^

Note it starts at a whitespace after the ->.
I think it should just include the ->, i.e. return ["-e", 1, 2, 1, 10].
Or possibly start at the {, i.e. return ["-e", 1, 3, 1, 10].
But starting on a whitespace like here seems really strange, it looks like a bug.

It's the same result with --parser=parse.y, so I don't show it.


For context:
For Procs/block it looks like this:

$ ruby -e 'p proc { a }.source_location'
["-e", 1, 7, 1, 12]
p proc { a }.source_location
       ^^^^^

This looks fine.
The block could of course be given to any other method so it won't always be proc in front.
Maybe it could include the method too (so it would return start column 2 here), I think either is fine.

For for blocks it looks like this:

$ ruby -e '                                                             
def self.each(&b); yield b; end;
for b in self
  42
end
p b.source_location'
["-e", 3, 0, 5, 3]

That is, it covers the entire for expression from for until end.
I think that's good and fine as-is.

For def methods it covers everything from def to end (or end of line for def m = 42), as expected.


Related issues 2 (2 open0 closed)

Related to Ruby - Feature #21005: Update the source location method to include line start/stop and column start/stop detailsOpenActions
Related to Ruby - Feature #6012: Proc#source_location also return the columnOpennobu (Nobuyoshi Nakada)Actions
Actions

Also available in: PDF Atom