[ruby-core:124460] [Ruby Feature#6012] Proc#source_location also return the column
Issue #6012 has been updated by mame (Yusuke Endoh). Eregon (Benoit Daloze) wrote in #note-49:
In any case I don't think it's our place to judge whether each usage is "valid" or "correct" or not, it's definitely useful functionality since it's used so much.
"I don't know exactly what users are using the `method_source` gem for, but since it's used so much, we should provide equivalent functionality as a built-in feature" This argument can hardly persuade anyone... However, let’s assume we proceed with that logic. In that case, `source_location` would have to follow the behavior of the `method_source` gem exactly, without questioning its validity (including heredocs and the glitch-like behavior you pointed out). Since we do not know the user's ultimate purpose, there is a possibility that those glitch-like behaviors happen to be exactly what satisfies the user. Is that really what you want?
Nobody expects the `StatementsNode` instead of the `CallNode` for `Prism.node_for(Proc)`.
To give an extreme example, suppose we implement a TracePoint like `:ast_node_enter` that fires every time the interpreter evaluates each Prism node (as like a tree-walking interpreter). In that scenario, `Prism.node_for(TracePoint)` would need to distinguish between a `StatementsNode` and a `CallNode`. Also, Ruby's grammar will certainly continue to change, and I have no doubt that the instances of overlapping Nodes, beyond just `StatementsNode` and `CallNode`, can increase accordingly.
I do agree with you that for final use case of getting a Prism AST, #21795 would be more direct and safer (e.g. can check hash of the file). And there it's totally fine to use `node_id` internally on CRuby, as it remains an implementation detail not exposed to the user.
I agree with this. While #21795 seems like a heavy task with many issues to resolve, I think it is a sound approach in the sense that it is better to hide the implementation details of how to map Ruby objects to AST nodes. ---------------------------------------- Feature #6012: Proc#source_location also return the column https://bugs.ruby-lang.org/issues/6012#change-116011 * 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)
-
mame (Yusuke Endoh)