ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "Earlopain (A S) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "Earlopain (A S)" <noreply@ruby-lang.org>
Subject: [ruby-core:119317] [Ruby master Bug#20761] [DOC] `RubyVM::AbstractSyntaxTree.of` examples raise because parser is prism by default
Date: Fri, 27 Sep 2024 14:44:52 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-109927.20240927144451.53314@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-20761.20240926153835.53314@ruby-lang.org>

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})
# => <internal:ast>: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/

  parent reply	other threads:[~2024-09-27 14:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-26 15:38 [ruby-core:119301] " Earlopain (A S) via ruby-core
2024-09-26 15:47 ` [ruby-core:119302] " kddnewton (Kevin Newton) via ruby-core
2024-09-26 16:17 ` [ruby-core:119303] " Earlopain (A S) via ruby-core
2024-09-26 16:25 ` [ruby-core:119304] " kddnewton (Kevin Newton) via ruby-core
2024-09-26 16:25 ` [ruby-core:119306] " kddnewton (Kevin Newton) via ruby-core
2024-09-26 16:35 ` [ruby-core:119307] " Earlopain (A S) via ruby-core
2024-09-26 19:37 ` [ruby-core:119309] " kddnewton (Kevin Newton) via ruby-core
2024-09-27 14:30 ` [ruby-core:119315] " Eregon (Benoit Daloze) via ruby-core
2024-09-27 14:37 ` [ruby-core:119316] " Eregon (Benoit Daloze) via ruby-core
2024-09-27 14:44 ` Earlopain (A S) via ruby-core [this message]
2024-09-27 15:00 ` [ruby-core:119319] " Eregon (Benoit Daloze) via ruby-core

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-109927.20240927144451.53314@ruby-lang.org \
    --to=ruby-core@ml.ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).