From: "Earlopain (A S) via ruby-core" Date: 2024-09-27T14:44:52+00:00 Subject: [ruby-core:119317] [Ruby master Bug#20761] [DOC] `RubyVM::AbstractSyntaxTree.of` examples raise because parser is prism by default Issue #20761 has been updated by Earlopain (A S). Eregon (Benoit Daloze) wrote in #note-7: > @Earlopain Is there a reason you need this and cannot just use e.g. `Prism.parse("proc {1 + 2}")`? > > A cleaner and portable way to achieve this functionality from a Proc/Method would be if there is a way to retrieve their precise source location, i.e. start & end byte offsets or equivalent (`#source_location` currently only gives the start line and column). This question specifically was about usage that Rails recently adopted for printing the source code of a proc when doing `assert_no_difference(-> { foo })` inside the assertion error message. https://github.com/rails/rails/pull/52036. kddnewton has since raised a PR switching it over to `RubyVM::InstructionSequence` which of course has the same interoperability problems. https://github.com/rails/rails/pull/53055 If `source_location` would provide richer information, then it would be an easy switch. The PR basically already doing that through `:code_location` from the iseq. I remember an issue about it, maybe this https://bugs.ruby-lang.org/issues/8751, though I thought it was a bit more recently discussed. ---------------------------------------- Bug #20761: [DOC] `RubyVM::AbstractSyntaxTree.of` examples raise because parser is prism by default https://bugs.ruby-lang.org/issues/20761#change-109927 * Author: Earlopain (A S) * Status: Closed * ruby -v: 3.4-dev * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- https://docs.ruby-lang.org/en/master/RubyVM/AbstractSyntaxTree.html#method-c-of ```rb RubyVM::AbstractSyntaxTree.of(proc {1 + 2}) # => :97:in 'RubyVM::AbstractSyntaxTree.of': cannot get AST for ISEQ compiled by prism (RuntimeError) ``` Same for the method example. Is this method even functional when prism is used, or is the prism gem able to do this somehow? -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/