summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--io.c6
-rw-r--r--ruby.c3
-rw-r--r--test/ruby/test_argf.rb11
3 files changed, 20 insertions, 0 deletions
diff --git a/io.c b/io.c
index efe1ad944a..fe0652f233 100644
--- a/io.c
+++ b/io.c
@@ -9866,6 +9866,12 @@ argf_lineno_setter(VALUE val, ID id, VALUE *var)
ARGF.last_lineno = ARGF.lineno = n;
}
+void
+rb_reset_argf_lineno(long n)
+{
+ ARGF.last_lineno = ARGF.lineno = n;
+}
+
static VALUE argf_gets(int, VALUE *, VALUE);
/*
diff --git a/ruby.c b/ruby.c
index 0b6843d539..51921ffbe5 100644
--- a/ruby.c
+++ b/ruby.c
@@ -2151,6 +2151,8 @@ warn_cr_in_shebang(const char *str, long len)
#define warn_cr_in_shebang(str, len) (void)0
#endif
+void rb_reset_argf_lineno(long n);
+
struct load_file_arg {
VALUE parser;
VALUE fname;
@@ -2247,6 +2249,7 @@ load_file_internal(VALUE argp_v)
if (NIL_P(c)) {
argp->f = f = Qnil;
}
+ rb_reset_argf_lineno(0);
ruby_opt_init(opt);
}
if (opt->src.enc.index >= 0) {
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index dbffd24370..12f7d6485a 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -143,6 +143,17 @@ class TestArgf < Test::Unit::TestCase
};
end
+ def test_lineno_after_shebang
+ expected = %w"1 1 1 2 2 2 3 3 1 4 4 2"
+ assert_in_out_err(["--enable=gems", "-", @t1.path, @t2.path], "#{<<~"{#"}\n#{<<~'};'}", expected)
+ #!/usr/bin/env ruby
+ {#
+ ARGF.each do |line|
+ puts [$., ARGF.lineno, ARGF.file.lineno]
+ end
+ };
+ end
+
def test_new_lineno_each
f = ARGF.class.new(@t1.path, @t2.path, @t3.path)
result = []