1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nobu 2011-12-13 15:01:20 +00:00
parent 3dd1e6a91b
commit d62f56b041
4 changed files with 77 additions and 28 deletions

View file

@ -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> 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 * error.c (name_err_mesg_to_str): clear rb_thread_t::errinfo when

70
parse.y
View file

@ -3645,33 +3645,51 @@ block_call : command do_block
} }
; ;
method_call : operation paren_args method_call : operation
{ {
/*%%%*/ /*%%%*/
$$ = NEW_FCALL($1, $2); $<num>$ = ruby_sourceline;
fixpos($$, $2); /*% %*/
}
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); $<num>$ = ruby_sourceline;
fixpos($$, $1); /*% %*/
}
opt_paren_args
{
/*%%%*/
$$ = NEW_CALL($1, $3, $5);
nd_set_line($$, $<num>4);
/*% /*%
$$ = dispatch3(call, $1, ripper_id2sym('.'), $3); $$ = 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); $<num>$ = ruby_sourceline;
fixpos($$, $1); /*% %*/
}
paren_args
{
/*%%%*/
$$ = NEW_CALL($1, $3, $5);
nd_set_line($$, $<num>4);
/*% /*%
$$ = dispatch3(call, $1, ripper_id2sym('.'), $3); $$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
$$ = method_optarg($$, $4); $$ = method_optarg($$, $5);
%*/ %*/
} }
| primary_value tCOLON2 operation3 | primary_value tCOLON2 operation3
@ -3682,26 +3700,38 @@ method_call : operation paren_args
$$ = dispatch3(call, $1, ripper_intern("::"), $3); $$ = dispatch3(call, $1, ripper_intern("::"), $3);
%*/ %*/
} }
| primary_value '.' paren_args | primary_value '.'
{ {
/*%%%*/ /*%%%*/
$$ = NEW_CALL($1, rb_intern("call"), $3); $<num>$ = ruby_sourceline;
fixpos($$, $1); /*% %*/
}
paren_args
{
/*%%%*/
$$ = NEW_CALL($1, rb_intern("call"), $4);
nd_set_line($$, $<num>3);
/*% /*%
$$ = dispatch3(call, $1, ripper_id2sym('.'), $$ = dispatch3(call, $1, ripper_id2sym('.'),
ripper_intern("call")); ripper_intern("call"));
$$ = method_optarg($$, $3); $$ = method_optarg($$, $4);
%*/ %*/
} }
| primary_value tCOLON2 paren_args | primary_value tCOLON2
{ {
/*%%%*/ /*%%%*/
$$ = NEW_CALL($1, rb_intern("call"), $3); $<num>$ = ruby_sourceline;
fixpos($$, $1); /*% %*/
}
paren_args
{
/*%%%*/
$$ = NEW_CALL($1, rb_intern("call"), $4);
nd_set_line($$, $<num>3);
/*% /*%
$$ = dispatch3(call, $1, ripper_intern("::"), $$ = dispatch3(call, $1, ripper_intern("::"),
ripper_intern("call")); ripper_intern("call"));
$$ = method_optarg($$, $3); $$ = method_optarg($$, $4);
%*/ %*/
} }
| keyword_super paren_args | keyword_super paren_args

View file

@ -825,4 +825,18 @@ x = __ENCODING__
c.instance_eval { remove_class_variable(:@var) } c.instance_eval { remove_class_variable(:@var) }
end end
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 end

View file

@ -23,7 +23,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
4: x = 1 + 1 4: x = 1 + 1
5: set_trace_func(nil) 5: set_trace_func(nil)
EOF EOF
assert_equal(["c-return", 3, :set_trace_func, Kernel], assert_equal(["c-return", 1, :set_trace_func, Kernel],
events.shift) events.shift)
assert_equal(["line", 4, __method__, self.class], assert_equal(["line", 4, __method__, self.class],
events.shift) events.shift)
@ -50,7 +50,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
7: x = add(1, 1) 7: x = add(1, 1)
8: set_trace_func(nil) 8: set_trace_func(nil)
EOF EOF
assert_equal(["c-return", 3, :set_trace_func, Kernel], assert_equal(["c-return", 1, :set_trace_func, Kernel],
events.shift) events.shift)
assert_equal(["line", 4, __method__, self.class], assert_equal(["line", 4, __method__, self.class],
events.shift) events.shift)
@ -90,7 +90,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
8: x = Foo.new.bar 8: x = Foo.new.bar
9: set_trace_func(nil) 9: set_trace_func(nil)
EOF EOF
assert_equal(["c-return", 3, :set_trace_func, Kernel], assert_equal(["c-return", 1, :set_trace_func, Kernel],
events.shift) events.shift)
assert_equal(["line", 4, __method__, self.class], assert_equal(["line", 4, __method__, self.class],
events.shift) events.shift)
@ -143,7 +143,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
9: foo(false) 9: foo(false)
10: set_trace_func(nil) 10: set_trace_func(nil)
EOF EOF
assert_equal(["c-return", 3, :set_trace_func, Kernel], assert_equal(["c-return", 1, :set_trace_func, Kernel],
events.shift) events.shift)
assert_equal(["line", 4, __method__, self.class], assert_equal(["line", 4, __method__, self.class],
events.shift) events.shift)
@ -187,7 +187,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
8: foo 8: foo
9: set_trace_func(nil) 9: set_trace_func(nil)
EOF EOF
assert_equal(["c-return", 3, :set_trace_func, Kernel], assert_equal(["c-return", 1, :set_trace_func, Kernel],
events.shift) events.shift)
assert_equal(["line", 4, __method__, self.class], assert_equal(["line", 4, __method__, self.class],
events.shift) events.shift)
@ -224,7 +224,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
7: end 7: end
8: set_trace_func(nil) 8: set_trace_func(nil)
EOF EOF
assert_equal(["c-return", 3, :set_trace_func, Kernel], assert_equal(["c-return", 1, :set_trace_func, Kernel],
events.shift) events.shift)
assert_equal(["line", 4, __method__, self.class], assert_equal(["line", 4, __method__, self.class],
events.shift) events.shift)
@ -273,7 +273,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
8: set_trace_func(nil) 8: set_trace_func(nil)
EOF EOF
[["c-return", 3, :set_trace_func, Kernel], [["c-return", 1, :set_trace_func, Kernel],
["line", 4, __method__, self.class], ["line", 4, __method__, self.class],
["c-call", 4, :any?, Enumerable], ["c-call", 4, :any?, Enumerable],
["c-call", 4, :each, Array], ["c-call", 4, :each, Array],
@ -367,7 +367,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
7: set_trace_func(nil) 7: set_trace_func(nil)
EOF EOF
[["c-return", 5, :set_trace_func, Kernel], [["c-return", 3, :set_trace_func, Kernel],
["line", 6, __method__, self.class], ["line", 6, __method__, self.class],
["call", 6, :foobar, FooBar], ["call", 6, :foobar, FooBar],
["return", 6, :foobar, FooBar], ["return", 6, :foobar, FooBar],