ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "tenderlovemaking (Aaron Patterson) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "tenderlovemaking (Aaron Patterson)" <noreply@ruby-lang.org>
Subject: [ruby-core:117714] [Ruby master Bug#20457] Final `return` is eliminated from the AST
Date: Thu, 25 Apr 2024 20:02:33 +0000 (UTC)	[thread overview]
Message-ID: <redmine.issue-20457.20240425200233.73@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-20457.20240425200233.73@ruby-lang.org

Issue #20457 has been reported by tenderlovemaking (Aaron Patterson).

----------------------------------------
Bug #20457: Final `return` is eliminated from the AST
https://bugs.ruby-lang.org/issues/20457

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
Given the following code:

```ruby
def foo
  a = 1
  return a
end
```

If you parse this with RubyVM::AbstractSyntaxTree, the AST will be missing the `return` node.  Of course the `return` node isn't necessary for compilation, but would be required for building an LSP for example.

Here's a full program to demonstrate:

```ruby
ast = RubyVM::AbstractSyntaxTree.parse DATA.read
pp ast

# Output is like this:
#
# (SCOPE@1:0-4:3
# tbl: []
# args: nil
# body:
#   (DEFN@1:0-4:3
#    mid: :foo
#    body:
#      (SCOPE@1:0-4:3
#       tbl: [:a]
#       args: (ARGS@1:7-1:7 pre_num: 0 pre_init: nil opt: nil first_post: nil post_num: 0 post_init: nil rest: nil kw: nil kwrest: nil block: nil)
#       body: (BLOCK@2:2-3:10 (LASGN@2:2-2:7 :a (INTEGER@2:6-2:7 1)) (LVAR@3:9-3:10 :a)))))

__END__
def foo
  a = 1
  return a
end
```

Btw, I'm happy to write failing tests for this type of stuff I'm just not sure where to put it! :)



-- 
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/postorius/lists/ruby-core.ml.ruby-lang.org/

       reply	other threads:[~2024-04-25 20:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25 20:02 tenderlovemaking (Aaron Patterson) via ruby-core [this message]
2024-04-26  6:16 ` [ruby-core:117718] [Ruby master Bug#20457] Final `return` is eliminated from the AST nobu (Nobuyoshi Nakada) via ruby-core
2024-04-26 17:21 ` [ruby-core:117729] " Eregon (Benoit Daloze) via ruby-core
2024-04-30 21:51 ` [ruby-core:117741] " tenderlovemaking (Aaron Patterson) 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-list from there: mbox

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

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

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

  git send-email \
    --in-reply-to=redmine.issue-20457.20240425200233.73@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    --cc=ruby-core@ml.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 read-only IMAP folder(s) and NNTP newsgroup(s).