From: "headius (Charles Nutter) via ruby-core" Date: 2025-03-31T22:52:19+00:00 Subject: [ruby-core:121493] [Ruby Feature#15574] Prohibit to pass a block on super() implicitly Issue #15574 has been updated by headius (Charles Nutter). There's still a problem here when an "unused block" warning is emitted from native code. The current behavior is actually quite counter-intuitive. Take this example of extending `Array` and overriding `index`. ```ruby class MyArray def index(arg) yield super(arg) end end MyArray.new([1]).index(1) {p it} ``` On all recent versions of Ruby, this will warn: ``` $ cx 3.4 ruby -v blah.rb ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24] blah.rb:3: warning: given block not used 0 ``` The only way to eliminate the warning is to explicitly *prevent* the block from being passed using `super(arg, &nil)`: ```ruby def index(arg) yield super(arg, &nil) end ``` I see in https://bugs.ruby-lang.org/issues/15554 that this special "implicit block" behavior for `super()` has been explicitly ignored for warning purposes, but there's clearly some problematic cases remaining here. We just addressed a user bug report where the native method warned even if no block was explicitly passed to `super()`: https://github.com/jruby/jruby/issues/8728 ---------------------------------------- Feature #15574: Prohibit to pass a block on super() implicitly https://bugs.ruby-lang.org/issues/15574#change-112514 * Author: ko1 (Koichi Sasada) * Status: Rejected * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- As described in [Feature #15554], `super()` (not `super`) pass the given block. ``` class C def foo p block_given? end end class C1 < C def foo super #=> true super() #=> true end end C1.new.foo{} ``` `super` (without parameters) passes all passed parameters so it is no surprise to pass given block. However, `super()` (with parameters. In this case, it passes 0 parameters) also pass given block implicitly. I'm not sure who use this behavior, but I think it is simple to prohibit such implicit block passing. -- 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/