summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-13 15:01:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-13 15:01:20 +0000
commitd62f56b04182f5b7b02944d5c169fe44513135b1 (patch)
tree73830445eb27610ab4a7a4bede497dea016f5153
parent3dd1e6a91bdd1d743c6f47c910e94b707b7eb190 (diff)
* parse.y (primary): point method name line. [ruby-core:40936]
[Bug #5614] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--parse.y70
-rw-r--r--test/ruby/test_parse.rb14
-rw-r--r--test/ruby/test_settracefunc.rb16
4 files changed, 77 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index 4a9f2097a1..23a3817d4c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Dec 14 00:01:15 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (primary): point method name line. [ruby-core:40936]
+ [Bug #5614]
+
Tue Dec 13 23:43:48 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
* error.c (name_err_mesg_to_str): clear rb_thread_t::errinfo when
diff --git a/parse.y b/parse.y
index c3701124ff..36bdd49370 100644
--- a/parse.y
+++ b/parse.y
@@ -3645,33 +3645,51 @@ block_call : command do_block
}
;
-method_call : operation paren_args
+method_call : operation
{
/*%%%*/
- $$ = NEW_FCALL($1, $2);
- fixpos($$, $2);
+ $<num>$ = ruby_sourceline;
+ /*% %*/
+ }
+ paren_args
+ {
+ /*%%%*/
+ $$ = NEW_FCALL($1, $3);
+ nd_set_line($$, $<num>2);
/*%
- $$ = method_arg(dispatch1(fcall, $1), $2);
+ $$ = method_arg(dispatch1(fcall, $1), $3);
%*/
}
- | primary_value '.' operation2 opt_paren_args
+ | primary_value '.' operation2
{
/*%%%*/
- $$ = NEW_CALL($1, $3, $4);
- fixpos($$, $1);
+ $<num>$ = ruby_sourceline;
+ /*% %*/
+ }
+ opt_paren_args
+ {
+ /*%%%*/
+ $$ = NEW_CALL($1, $3, $5);
+ nd_set_line($$, $<num>4);
/*%
$$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
- $$ = method_optarg($$, $4);
+ $$ = method_optarg($$, $5);
%*/
}
- | primary_value tCOLON2 operation2 paren_args
+ | primary_value tCOLON2 operation2
{
/*%%%*/
- $$ = NEW_CALL($1, $3, $4);
- fixpos($$, $1);
+ $<num>$ = ruby_sourceline;
+ /*% %*/
+ }
+ paren_args
+ {
+ /*%%%*/
+ $$ = NEW_CALL($1, $3, $5);
+ nd_set_line($$, $<num>4);
/*%
$$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
- $$ = method_optarg($$, $4);
+ $$ = method_optarg($$, $5);
%*/
}
| primary_value tCOLON2 operation3
@@ -3682,26 +3700,38 @@ method_call : operation paren_args
$$ = dispatch3(call, $1, ripper_intern("::"), $3);
%*/
}
- | primary_value '.' paren_args
+ | primary_value '.'
{
/*%%%*/
- $$ = NEW_CALL($1, rb_intern("call"), $3);
- fixpos($$, $1);
+ $<num>$ = ruby_sourceline;
+ /*% %*/
+ }
+ paren_args
+ {
+ /*%%%*/
+ $$ = NEW_CALL($1, rb_intern("call"), $4);
+ nd_set_line($$, $<num>3);
/*%
$$ = dispatch3(call, $1, ripper_id2sym('.'),
ripper_intern("call"));
- $$ = method_optarg($$, $3);
+ $$ = method_optarg($$, $4);
%*/
}
- | primary_value tCOLON2 paren_args
+ | primary_value tCOLON2
{
/*%%%*/
- $$ = NEW_CALL($1, rb_intern("call"), $3);
- fixpos($$, $1);
+ $<num>$ = ruby_sourceline;
+ /*% %*/
+ }
+ paren_args
+ {
+ /*%%%*/
+ $$ = NEW_CALL($1, rb_intern("call"), $4);
+ nd_set_line($$, $<num>3);
/*%
$$ = dispatch3(call, $1, ripper_intern("::"),
ripper_intern("call"));
- $$ = method_optarg($$, $3);
+ $$ = method_optarg($$, $4);
%*/
}
| keyword_super paren_args
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 14990be12c..f0f872013d 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -825,4 +825,18 @@ x = __ENCODING__
c.instance_eval { remove_class_variable(:@var) }
end
end
+
+ def test_method_block_location
+ bug5614 = '[ruby-core:40936]'
+ expected = nil
+ e = assert_raise(NoMethodError) do
+ 1.times do
+ expected = __LINE__+1
+ end.print do
+ #
+ end
+ end
+ actual = e.backtrace.first[/\A#{Regexp.quote(__FILE__)}:(\d+):/o, 1].to_i
+ assert_equal(expected, actual, bug5614)
+ end
end
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb
index d6c6d06f38..f53b62f166 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -23,7 +23,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
4: x = 1 + 1
5: set_trace_func(nil)
EOF
- assert_equal(["c-return", 3, :set_trace_func, Kernel],
+ assert_equal(["c-return", 1, :set_trace_func, Kernel],
events.shift)
assert_equal(["line", 4, __method__, self.class],
events.shift)
@@ -50,7 +50,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
7: x = add(1, 1)
8: set_trace_func(nil)
EOF
- assert_equal(["c-return", 3, :set_trace_func, Kernel],
+ assert_equal(["c-return", 1, :set_trace_func, Kernel],
events.shift)
assert_equal(["line", 4, __method__, self.class],
events.shift)
@@ -90,7 +90,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
8: x = Foo.new.bar
9: set_trace_func(nil)
EOF
- assert_equal(["c-return", 3, :set_trace_func, Kernel],
+ assert_equal(["c-return", 1, :set_trace_func, Kernel],
events.shift)
assert_equal(["line", 4, __method__, self.class],
events.shift)
@@ -143,7 +143,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
9: foo(false)
10: set_trace_func(nil)
EOF
- assert_equal(["c-return", 3, :set_trace_func, Kernel],
+ assert_equal(["c-return", 1, :set_trace_func, Kernel],
events.shift)
assert_equal(["line", 4, __method__, self.class],
events.shift)
@@ -187,7 +187,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
8: foo
9: set_trace_func(nil)
EOF
- assert_equal(["c-return", 3, :set_trace_func, Kernel],
+ assert_equal(["c-return", 1, :set_trace_func, Kernel],
events.shift)
assert_equal(["line", 4, __method__, self.class],
events.shift)
@@ -224,7 +224,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
7: end
8: set_trace_func(nil)
EOF
- assert_equal(["c-return", 3, :set_trace_func, Kernel],
+ assert_equal(["c-return", 1, :set_trace_func, Kernel],
events.shift)
assert_equal(["line", 4, __method__, self.class],
events.shift)
@@ -273,7 +273,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
8: set_trace_func(nil)
EOF
- [["c-return", 3, :set_trace_func, Kernel],
+ [["c-return", 1, :set_trace_func, Kernel],
["line", 4, __method__, self.class],
["c-call", 4, :any?, Enumerable],
["c-call", 4, :each, Array],
@@ -367,7 +367,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
7: set_trace_func(nil)
EOF
- [["c-return", 5, :set_trace_func, Kernel],
+ [["c-return", 3, :set_trace_func, Kernel],
["line", 6, __method__, self.class],
["call", 6, :foobar, FooBar],
["return", 6, :foobar, FooBar],