[ruby-core:125038] [Ruby Feature#6012] Proc#source_location also return the column
Issue #6012 has been updated by matz (Yukihiro Matsumoto). Thank you, @eregon, for the thorough analysis and for pushing this feature forward with such persistence over the years. I have reconsidered my position. Although I approved this change, and it has been in master for a year, I now believe extending the existing `source_location` return value from 2 elements to 5 is the wrong approach. The information itself is not undesirable, but the API design is unsound. The evidence in #note-43 is difficult to dismiss. The idiom `obj.source_location.last` is pervasive across the gem ecosystem, not only in test files but in production library code. Returning `end_column` from `.last` instead of `lineno` is an unexpected semantic shift. Even if every well-maintained gem has been patched, user application code in the wild cannot be audited or fixed centrally. This is the kind of silent, hard-to-debug breakage that I find particularly regrettable. I understand @eregon 's argument that the breakage is small in practice, and that the feature has been available in previews without major complaints. But my concern is not just about breakage that has already surfaced. It is also about breakage that has not surfaced yet, in private codebases and unmaintained gems. More fundamentally, `source_location` was designed as a 2-element tuple, and that contract is now baked deeply into the ecosystem. Extending it is technically a compatible addition, but idiomatically it is a breaking change for any code that treats the array positionally. Therefore, I am reverting this change for now. I would like to introduce the additional information through a new, dedicated API instead, something like `source_range` returning an object with `start_line`, `start_column`, `end_line`, `end_column` as named attributes, or a `Ruby::SourceLocation` class as discussed in related issues. This approach keeps `source_location` stable and backward-compatible, makes the richer information explicitly opt-in, and allows us to design the API properly (e.g., bytes vs. characters, what to expose for `Binding`, etc.) without rushing. I know this is frustrating after 14 years and two approvals. I am sorry for the back-and-forth. The use cases are real and I want to support them, just through a cleaner API that does not carry this compatibility risk. Matz. ---------------------------------------- Feature #6012: Proc#source_location also return the column https://bugs.ruby-lang.org/issues/6012#change-116735 * Author: rogerdpack (Roger Pack) * Status: Closed * Assignee: nobu (Nobuyoshi Nakada) ---------------------------------------- As originally suggested in http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/42418 Suggestion/feature request: have #source_location also return the beginning column where it was defined. ["test.rb", 8, 33] Thanks! -roger- -- https://bugs.ruby-lang.org/
participants (1)
-
matz (Yukihiro Matsumoto)