diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-19 07:59:07 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-19 07:59:07 +0000 |
commit | 5cda4e90714fedc78abb0426c2ab932bf113fb2d (patch) | |
tree | afbef84ccbbec9083d3e5054366abb753fb0f024 | |
parent | eb568bdee620e2efcd6405a98c96cbe117c9d5e3 (diff) | |
download | ruby-5cda4e90714fedc78abb0426c2ab932bf113fb2d.tar.gz |
parse.y: adjust position of lambda
* parse.y (lambda): adjust position to the beginning of the block.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | parse.y | 8 | ||||
-rw-r--r-- | test/ruby/test_lambda.rb | 24 |
3 files changed, 34 insertions, 2 deletions
@@ -1,3 +1,7 @@ +Thu Sep 19 16:59:02 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * parse.y (lambda): adjust position to the beginning of the block. + Thu Sep 19 16:25:06 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> * vsnprintf.c (BSD_vfprintf): initialize cp so that size is 0 in the @@ -3460,13 +3460,17 @@ lambda : { lpar_beg = ++paren_nest; } f_larglist + { + $<num>$ = ruby_sourceline; + } lambda_body { lpar_beg = $<num>2; /*%%%*/ - $$ = NEW_LAMBDA($3, $4); + $$ = NEW_LAMBDA($3, $5); + nd_set_line($$, $<num>4); /*% - $$ = dispatch2(lambda, $3, $4); + $$ = dispatch2(lambda, $3, $5); %*/ dyna_pop($<vars>1); } diff --git a/test/ruby/test_lambda.rb b/test/ruby/test_lambda.rb index f042ab015e..6023c3fcc8 100644 --- a/test/ruby/test_lambda.rb +++ b/test/ruby/test_lambda.rb @@ -109,4 +109,28 @@ class TestLambdaParameters < Test::Unit::TestCase assert_equal(42, return_in_current(42), feature8693) assert_equal(42, return_in_callee(42), feature8693) end + + def test_do_lambda_source_location + exp_lineno = __LINE__ + 3 + lmd = ->(x, + y, + z) do + # + end + file, lineno = lmd.source_location + assert_match(/^#{ Regexp.quote(__FILE__) }$/, file) + assert_equal(exp_lineno, lineno, "must be ") + end + + def test_brace_lambda_source_location + exp_lineno = __LINE__ + 3 + lmd = ->(x, + y, + z) { + # + } + file, lineno = lmd.source_location + assert_match(/^#{ Regexp.quote(__FILE__) }$/, file) + assert_equal(exp_lineno, lineno, "must be ") + end end |