From: ko1@atdot.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:91121] [Ruby trunk Bug#15539] Proc.new with no block shouldn't always warn
Date: Wed, 16 Jan 2019 10:12:46 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-76353.20190116101244.cf1f48fad42db64c@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15539.20190115230458@ruby-lang.org
Issue #15539 has been updated by ko1 (Koichi Sasada).
Status changed from Open to Rejected
> makes it no longer possible to have a default value for a positional argument that uses the block
Surprisingly, we can:
```
def foo o = binding.local_variable_get(:b), &b
p o.class
end
foo{} #=> Proc
```
(of course it is joke code. it is too implementation dependent code so we shouldn't rely on this behavior)
Anyway, I close this ticket and discuss more on new ticket I'll file.
Thanks,
Koichi
----------------------------------------
Bug #15539: Proc.new with no block shouldn't always warn
https://bugs.ruby-lang.org/issues/15539#change-76353
* Author: tenderlovemaking (Aaron Patterson)
* Status: Rejected
* Priority: Normal
* Assignee:
* Target version:
* ruby -v:
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hi,
r66772 introduced a warning for the following code:
``` ruby
def foo bar = Proc.new
bar.call
end
foo { p "block" } # warn
foo ->() { p "block" } # no warn
```
I don't think this case of `Proc.new` should warn. To eliminate warnings, I have to rewrite as:
``` ruby
def foo bar = nil
if bar
bar.call
else
yield
end
end
```
Rails uses this "Proc.new" trick here:
* https://github.com/rails/rails/blob/a08827a90b5a9be79379019cf5b242bd7236d2e3/actionpack/lib/action_controller/metal.rb#L29
* https://github.com/rails/rails/blob/a08827a90b5a9be79379019cf5b242bd7236d2e3/actionpack/lib/action_dispatch/middleware/stack.rb#L100
* https://github.com/rails/rails/blob/a08827a90b5a9be79379019cf5b242bd7236d2e3/activerecord/lib/active_record/statement_cache.rb#L116
* https://github.com/rails/rails/blob/a08827a90b5a9be79379019cf5b242bd7236d2e3/activesupport/lib/active_support/notifications/fanout.rb#L21
I can change Rails, but I want to know why and I don't see any discussion of r66772 (the commit doesn't have a feature number).
Thanks!
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2019-01-16 10:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-15539.20190115230458@ruby-lang.org>
2019-01-15 23:04 ` [ruby-core:91109] [Ruby trunk Bug#15539] Proc.new with no block shouldn't always warn tenderlove
2019-01-16 0:25 ` [ruby-core:91112] " ko1
2019-01-16 1:03 ` [ruby-core:91113] " tenderlove
2019-01-16 1:33 ` [ruby-core:91114] " merch-redmine
2019-01-16 10:12 ` ko1 [this message]
2019-01-16 10:20 ` [ruby-core:91122] " eregontp
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.journal-76353.20190116101244.cf1f48fad42db64c@ruby-lang.org \
--to=ruby-core@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).