From 9ad065375f171ea37979d31ef725323b3b7414e9 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 4 Dec 2009 07:50:15 +0000 Subject: [PATCH] * parse.y (k_def): adjust the location of method definition to the line of def. [Bug #2427] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ parse.y | 8 ++++++-- test/ruby/test_proc.rb | 7 ++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 694139070a..bb08f99c41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Dec 4 16:50:13 2009 Nobuyoshi Nakada + + * parse.y (k_def): adjust the location of method definition to the + line of def. [Bug #2427] + Fri Dec 4 15:50:18 2009 Shugo Maeda * vm_eval.c (yield_under): does not yield self, and passes blockptr diff --git a/parse.y b/parse.y index b194f49611..8451eb17d5 100644 --- a/parse.y +++ b/parse.y @@ -2902,7 +2902,7 @@ primary : literal NODE *body = remove_begin($5); reduce_nodes(&body); $$ = NEW_DEFN($2, $4, body, NOEX_PRIVATE); - fixpos($$, $4); + nd_set_line($$, $1); /*% $$ = dispatch3(def, $2, $4, $5); %*/ @@ -2924,7 +2924,7 @@ primary : literal NODE *body = remove_begin($8); reduce_nodes(&body); $$ = NEW_DEFS($2, $5, $7, body); - fixpos($$, $2); + nd_set_line($$, $1); /*% $$ = dispatch5(defs, $2, $3, $5, $7, $8); %*/ @@ -3034,6 +3034,10 @@ k_module : keyword_module k_def : keyword_def { token_info_push("def"); + /*%%%*/ + $$ = ruby_sourceline; + /*% + %*/ } ; diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 6c2bae4c41..de95ed5676 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -746,14 +746,15 @@ class TestProc < Test::Unit::TestCase assert(x.to_s.tainted?) end - def source_location_test - __LINE__ + @@line_of_source_location_test = __LINE__ + 1 + def source_location_test a=1, + b=2 end def test_source_location file, lineno = method(:source_location_test).source_location assert_match(/^#{ Regexp.quote(__FILE__) }$/, file) - assert_equal(source_location_test - 1, lineno) + assert_equal(@@line_of_source_location_test, lineno, 'Bug #2427') end def test_splat_without_respond_to