Project

General

Profile

Actions

Bug #4225

closed

IO.foreach should only accept string arguments

Added by djberg96 (Daniel Berger) about 13 years ago. Updated almost 10 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?

Actions #1

Updated by nobu (Nobuyoshi Nakada) about 13 years ago

  • Target version changed from Ruby 1.8.7 to Ruby 1.8.8
Actions #2

Updated by shyouhei (Shyouhei Urabe) over 10 years ago

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

I guess this one still occurs?

Updated by djberg96 (Daniel Berger) almost 10 years ago

Still happening as of 2.1.2.

Updated by nobu (Nobuyoshi Nakada) almost 10 years ago

  • 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) almost 10 years ago

Why do they defer?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0