Skip to content

Commit 53de964

Browse files
committed
mruby-io/io.c (io_init): File.new should not take blocks
1 parent 6718788 commit 53de964

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

mrbgems/mruby-io/src/io.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,9 @@ io_init(mrb_state *mrb, mrb_value io)
706706

707707
mode = opt = mrb_nil_value();
708708

709+
if (mrb_block_given_p(mrb)) {
710+
mrb_warn(mrb, "File.new() does not take block; use File.open() instead");
711+
}
709712
mrb_get_args(mrb, "i|oH", &fd, &mode, &opt);
710713
switch (fd) {
711714
case 0: /* STDIN_FILENO */

mrbgems/mruby-io/test/io.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ def assert_io_open(meth)
1616
io1.close
1717
end
1818

19-
io2 = IO.__send__(meth, IO.sysopen($mrbtest_io_rfname))do |io|
20-
if meth == :open
21-
assert_equal $mrbtest_io_msg, io.read
22-
else
23-
flunk "IO.#{meth} does not take block"
19+
if meth == :open
20+
io2 = IO.__send__(meth, IO.sysopen($mrbtest_io_rfname))do |io|
21+
if meth == :open
22+
assert_equal $mrbtest_io_msg, io.read
23+
else
24+
flunk "IO.#{meth} does not take block"
25+
end
2426
end
2527
end
26-
io2.close unless meth == :open
2728

2829
assert_raise(RuntimeError) { IO.__send__(meth, 1023) } # For Windows
2930
assert_raise(RuntimeError) { IO.__send__(meth, 1 << 26) }

0 commit comments

Comments
 (0)