Skip to content

Commit 34e127f

Browse files
committed
[GR-18163] Fix 'given block not used' warning in Enumerable#inject
PullRequest: truffleruby/3640
2 parents d28f52a + 5e7ce29 commit 34e127f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/ruby/truffleruby/core/enumerable.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,15 @@ def inject(initial=undefined, sym=undefined, &block)
510510
return Primitive.array_inject(self, initial, sym, block)
511511
end
512512

513+
if !Primitive.undefined?(sym) && block_given?
514+
warn 'given block not used', uplevel: 1
515+
end
516+
513517
if !block_given? or !Primitive.undefined?(sym)
514518
if Primitive.undefined?(sym)
515519
raise ArgumentError, 'no block or symbol given' if Primitive.undefined?(initial)
516520
sym = initial
517521
initial = undefined
518-
else
519-
warn 'given block not used', uplevel: 1
520522
end
521523

522524
# Do the sym version

0 commit comments

Comments
 (0)