Project

General

Profile

Actions

Bug #21783

open

{Method,UnboundMethod,Proc}#source_location returns columns in bytes and not in characters

Bug #21783: {Method,UnboundMethod,Proc}#source_location returns columns in bytes and not in characters

Added by Eregon (Benoit Daloze) 1 day ago. Updated 37 minutes 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:124206]

Description

The documentation says:

= Proc.source_location

(from ruby core)
------------------------------------------------------------------------
  prc.source_location  -> [String, Integer, Integer, Integer, Integer]

------------------------------------------------------------------------

Returns the location where the Proc was defined. The returned Array
contains:
  (1) the Ruby source filename
  (2) the line number where the definition starts
  (3) the column number where the definition starts
  (4) the line number where the definition ends
  (5) the column number where the definitions ends

This method will return nil if the Proc was not defined in Ruby (i.e.
native).

So it talks about column numbers, so it should be a number of characters and not of bytes.

But currently it's a number of bytes:

$ ruby --parser=prism -ve 'def été; end; p method(:été).source_location'
ruby 4.0.0dev (2025-12-14T07:11:02Z master 711d14992e) +PRISM [x86_64-linux]
["-e", 1, 0, 1, 14]

$ ruby --parser=parse.y -ve 'def été; end; p method(:été).source_location'
ruby 4.0.0dev (2025-12-14T07:11:02Z master 711d14992e) [x86_64-linux]
["-e", 1, 0, 1, 14]

The last number should be 12 because "def été; end".size is 12 characters.

This is a Ruby-level API so I would never expect "byte columns" here, I think it's clear it should be a number of "editor columns" i.e. a number of characters.


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