Issue #21783 has been updated by Eregon (Benoit Daloze). mame (Yusuke Endoh) wrote in #note-22:
`source_location` does not uniquely identify a node. For example, code `x` is represented as an AST with three nodes: `ProgramNode`, `StatementsNode`, and `CallNode`. They all have the same `source_location`, so cannot be distinguished.
True but that's not a problem for `Prism.node_for(Method | UnboundMethod | Proc)` because it returns `DefNode | LambdaNode | CallNode | ForNode`, i.e. we choose the relevant node to return even if multiple nodes would have the same source location. And in general the user could choose that e.g. they want the outermost node, or a node of a specific node class. mame (Yusuke Endoh) wrote in #note-22:
[@ktsj (Kazuki Tsujimoto)](/users/3007) said that `assert { condition ? expected == actual : expected == actual }` cannot be distinguished at present.
That seems a separate and unrelated problem to having `assert { ... }; assert { ... }`. (BTW no multi-line block seems currently a big limitation for `power_assert`) For `assert { ... }; assert { ... }`, I'm convinced source_location with column information is helpful and a good portable solution. --- Is there any chance to merge https://github.com/ruby/ruby/pull/15580 before the 4.0.0 release? If not, it will establish a precedent of "asking clarification in an issue can result in removing a feature that has been on master for almost a year". I think that's a bad precedent to set, i.e. to remove features implemented for a long time at the last minute with little evidence of a problem and not even discussing before reverting. It's disrespectful of gems & users which have adapted to the changes. Especially after discussing the feature for years, it feels like a betrayal to remove it now. I think it might drive people away from Ruby. Concretely I don't see much the point to discuss features on this tracker if they can be removed in such a way. The only good out of that I could see is if somehow that results in adding `Ruby::CodeLocation` or so with an API [like this](https://bugs.ruby-lang.org/issues/6012#note-19) in 4.1. Or even in 4.0.X given it's a compatible change and CRuby doesn't follow SemVer anyway, so the 3rd component is a mix of SemVer minor/patch. That would then be more flexible and e.g. expose columns, offsets, etc by having various method, and remove the need for things like `RubyVM::InstructionSequence#script_lines` by having a proper replacement. In general the goal here is to avoid `RubyVM` since that's CRuby-only, experimental, unstable and shouldn't be used anyway. The documentation of `RubyVM` makes it clear it's only `debugging, prototyping, and research` and clearly it has been abused over and over, because there is no proper API for some things like column information. After years of discussions to make some progress in this area with `source_location` column information, it's disheartening to see it reverted at the last minute. ---------------------------------------- Bug #21783: {Method,UnboundMethod,Proc}#source_location returns columns in bytes and not in characters https://bugs.ruby-lang.org/issues/21783#change-115782 * Author: Eregon (Benoit Daloze) * Status: Open * ruby -v: ruby 4.0.0dev (2025-12-14T07:11:02Z master 711d14992e) +PRISM [x86_64-linux] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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. -- https://bugs.ruby-lang.org/