Project

General

Profile

Actions

Bug #4225

closed

IO.foreach should only accept string arguments

Bug #4225: IO.foreach should only accept string arguments

Added by djberg96 (Daniel Berger) almost 15 years ago. Updated over 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin8.11.1]
Backport:
[ruby-core:34004]

Description

It looks like the IO.foreach method doesn't check its argument type first if no block is provided:

fh = File.new('somefile.txt')

IO.foreach(fh.fileno) # Or, IO.foreach(999999999)
=> #<Enumerable::Enumerator:0x110b0d4>

IO.foreach(fh.fileno){ |line| p line }
TypeError: can't convert Fixnum into String

I'd flip these two lines in io.c:

RETURN_ENUMERATOR(self, argc, argv);
SafeStringValue(fname);

Otherwise, what am I enumerating?

Updated by nobu (Nobuyoshi Nakada) almost 15 years ago Actions #1

  • Target version changed from Ruby 1.8.7 to Ruby 1.8.8

Updated by shyouhei (Shyouhei Urabe) almost 12 years ago Actions #2

  • Project changed from 2 to Ruby
  • Category changed from core to core
  • Target version deleted (Ruby 1.8.8)

I guess this one still occurs?

Updated by djberg96 (Daniel Berger) over 11 years ago Actions #3 [ruby-core:62641]

Still happening as of 2.1.2.

Updated by nobu (Nobuyoshi Nakada) over 11 years ago Actions #4 [ruby-core:62645]

  • Description updated (diff)
  • Status changed from Open to Rejected

Not only IO.foreach, an enumerator defers argument check in general.

Updated by djberg96 (Daniel Berger) over 11 years ago Actions #5 [ruby-core:62650]

Why do they defer?

Actions

Also available in: PDF Atom