ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:91109] [Ruby trunk Bug#15539] Proc.new with no block shouldn't always warn
       [not found] <redmine.issue-15539.20190115230458@ruby-lang.org>
@ 2019-01-15 23:04 ` tenderlove
  2019-01-16  0:25 ` [ruby-core:91112] " ko1
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: tenderlove @ 2019-01-15 23:04 UTC (permalink / raw)
  To: ruby-core

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

----------------------------------------
Bug #15539: Proc.new with no block shouldn't always warn
https://bugs.ruby-lang.org/issues/15539

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:91112] [Ruby trunk Bug#15539] Proc.new with no block shouldn't always warn
       [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 ` ko1
  2019-01-16  1:03 ` [ruby-core:91113] " tenderlove
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: ko1 @ 2019-01-16  0:25 UTC (permalink / raw)
  To: ruby-core

Issue #15539 has been updated by ko1 (Koichi Sasada).


I'll file the reason soon.

Anyway, I recommend you to rewrite it with a block parameter:

```
def foo bar = nil, &b
  (b || bar).call
end

# or
def foo bar = nil, &b
  bar ||= b
  bar.call
end
```


----------------------------------------
Bug #15539: Proc.new with no block shouldn't always warn
https://bugs.ruby-lang.org/issues/15539#change-76346

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:91113] [Ruby trunk Bug#15539] Proc.new with no block shouldn't always warn
       [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 ` tenderlove
  2019-01-16  1:33 ` [ruby-core:91114] " merch-redmine
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: tenderlove @ 2019-01-16  1:03 UTC (permalink / raw)
  To: ruby-core

Issue #15539 has been updated by tenderlovemaking (Aaron Patterson).


ko1 (Koichi Sasada) wrote:
> I'll file the reason soon.
> 
> Anyway, I recommend you to rewrite it with a block parameter:
> 
> ```
> def foo bar = nil, &b
>   (b || bar).call
> end
> 
> # or
> def foo bar = nil, &b
>   bar ||= b
>   bar.call
> end
> ```

Ok, no problem!  I'll update Rails and reference the feature when posted. 😊

----------------------------------------
Bug #15539: Proc.new with no block shouldn't always warn
https://bugs.ruby-lang.org/issues/15539#change-76347

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:91114] [Ruby trunk Bug#15539] Proc.new with no block shouldn't always warn
       [not found] <redmine.issue-15539.20190115230458@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-01-16  1:03 ` [ruby-core:91113] " tenderlove
@ 2019-01-16  1:33 ` merch-redmine
  2019-01-16 10:12 ` [ruby-core:91121] " ko1
  2019-01-16 10:20 ` [ruby-core:91122] " eregontp
  5 siblings, 0 replies; 6+ messages in thread
From: merch-redmine @ 2019-01-16  1:33 UTC (permalink / raw)
  To: ruby-core

Issue #15539 has been updated by jeremyevans0 (Jeremy Evans).


ko1 (Koichi Sasada) wrote:
> I'll file the reason soon.
> 
> Anyway, I recommend you to rewrite it with a block parameter:
> 
> ```
> def foo bar = nil, &b
>   (b || bar).call
> end

I also ran into this issue as `Proc.new` was used in a few places in Sequel. Removing implicit block support for `Proc.new` makes it no longer possible to have a default value for a positional argument that uses the block, since the block argument variable is not set until after default values for positional arguments (e.g. https://github.com/jeremyevans/sequel/commit/34faf32c6eddc02d1499748a431f3fdf46bfc5a4#diff-29540b6b617d51d3f5356b1cdfc534b0L61).  I feel the loss of functionality is acceptable, since `Proc.new`'s implicit block support was fairly magical and not widely known/used.

----------------------------------------
Bug #15539: Proc.new with no block shouldn't always warn
https://bugs.ruby-lang.org/issues/15539#change-76348

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:91121] [Ruby trunk Bug#15539] Proc.new with no block shouldn't always warn
       [not found] <redmine.issue-15539.20190115230458@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-01-16  1:33 ` [ruby-core:91114] " merch-redmine
@ 2019-01-16 10:12 ` ko1
  2019-01-16 10:20 ` [ruby-core:91122] " eregontp
  5 siblings, 0 replies; 6+ messages in thread
From: ko1 @ 2019-01-16 10:12 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:91122] [Ruby trunk Bug#15539] Proc.new with no block shouldn't always warn
       [not found] <redmine.issue-15539.20190115230458@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2019-01-16 10:12 ` [ruby-core:91121] " ko1
@ 2019-01-16 10:20 ` eregontp
  5 siblings, 0 replies; 6+ messages in thread
From: eregontp @ 2019-01-16 10:20 UTC (permalink / raw)
  To: ruby-core

Issue #15539 has been updated by Eregon (Benoit Daloze).


I always thought Proc.new working without an explicit block was an unintended feature in MRI, and indeed fairly magical, so I support taking a more explicit way in 2.7.

----------------------------------------
Bug #15539: Proc.new with no block shouldn't always warn
https://bugs.ruby-lang.org/issues/15539#change-76354

* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-01-16 10:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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 ` [ruby-core:91121] " ko1
2019-01-16 10:20 ` [ruby-core:91122] " eregontp

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).