Skip to content

yield from Enumerator raises "no receiver given" #7576

@notEthan

Description

@notEthan

JRuby raises ArgumentError: no receiver given when an Enumerator yields an empty array to certain methods:

class Foo
  def self.enum
    yield []
  end
end
Foo.to_enum(:enum).any?(&:nil?)
ArgumentError: no receiver given
    enum at ./jruby enum test.rb:3
    each at org/jruby/RubyEnumerator.java:397
    any? at org/jruby/RubyEnumerable.java:1785
  <main> at ./jruby enum test.rb:6

This does not seem to happen yielding a non-empty array or yielding any other object I tried. It happens with Enumerable#any?, #all?, none? but not with #each or #select. It happens when the block is a symbol, but not with a proc invoking the same method.

It does also happen using Enumerator.new rather than Kernel#to_enum

Enumerator.new { |yielder| yielder.yield([]) }.any?(&:nil?)
ArgumentError: no receiver given
   yield at org/jruby/RubyYielder.java:115
  <main> at ./jruby enum test.rb:1
    each at org/jruby/RubyGenerator.java:98
    each at org/jruby/RubyEnumerator.java:397
    any? at org/jruby/RubyEnumerable.java:1785
  <main> at ./jruby enum test.rb:1

Environment Information

  • jruby -v: jruby 9.4.0.0 (3.1.0) 2022-11-23 95c0ec159f OpenJDK 64-Bit Server VM 17.0.5+8 on 17.0.5+8 +jit [x86_64-darwin]
  • uname -a: Darwin foo 21.6.0 Darwin Kernel Version 21.6.0: Sun Nov 6 23:31:16 PST 2022; root:xnu-8020.240.14~1/RELEASE_X86_64 x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions