summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-03 01:46:59 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-03 01:46:59 +0000
commit86bfcc2da07d524845fbfb3a458a84cc8bd3ecf1 (patch)
treef8253548080292e640e2405031c706cdff25b3f5
parent1281e56682692859e726e24fff30e44aac6f948b (diff)
merge revision(s) 58499,58500: [Backport #13181]
parse.y: fix line in rescue * parse.y (set_line_body, primary): fix line number of bodystmt as the beginning of the block. [ruby-core:79388] [Bug #13181] parse.y: set_line_body is not used in ripper git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@60626 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--parse.y20
-rw-r--r--test/ruby/test_parse.rb13
-rw-r--r--version.h8
3 files changed, 34 insertions, 7 deletions
diff --git a/parse.y b/parse.y
index cca5e58cde..ad70501fe3 100644
--- a/parse.y
+++ b/parse.y
@@ -397,6 +397,17 @@ static int parser_yyerror(struct parser_params*, const char*);
static int yylex(YYSTYPE*, struct parser_params*);
#ifndef RIPPER
+static inline void
+set_line_body(NODE *body, int line)
+{
+ if (!body) return;
+ switch (nd_type(body)) {
+ case NODE_RESCUE:
+ case NODE_ENSURE:
+ nd_set_line(body, line);
+ }
+}
+
#define yyparse ruby_yyparse
static NODE* node_newnode(struct parser_params *, enum node_type, VALUE, VALUE, VALUE);
@@ -2644,9 +2655,7 @@ primary : literal
$$ = NEW_NIL();
}
else {
- if (nd_type($3) == NODE_RESCUE ||
- nd_type($3) == NODE_ENSURE)
- nd_set_line($3, $<num>2);
+ set_line_body($3, $<num>2);
$$ = NEW_BEGIN($3);
}
nd_set_line($$, $<num>2);
@@ -2931,6 +2940,7 @@ primary : literal
{
/*%%%*/
$$ = NEW_CLASS($2, $5, $3);
+ set_line_body($5, $<num>4);
nd_set_line($$, $<num>4);
/*%
$$ = dispatch3(class, $2, $3, $5);
@@ -2950,6 +2960,7 @@ primary : literal
{
/*%%%*/
$$ = NEW_SCLASS($3, $6);
+ set_line_body($6, nd_line($3));
fixpos($$, $3);
/*%
$$ = dispatch2(sclass, $3, $6);
@@ -2973,6 +2984,7 @@ primary : literal
{
/*%%%*/
$$ = NEW_MODULE($2, $4);
+ set_line_body($4, $<num>3);
nd_set_line($$, $<num>3);
/*%
$$ = dispatch2(module, $2, $4);
@@ -2997,6 +3009,7 @@ primary : literal
NODE *body = remove_begin($6);
reduce_nodes(&body);
$$ = NEW_DEFN($2, $5, body, METHOD_VISI_PRIVATE);
+ set_line_body(body, $<num>1);
nd_set_line($$, $<num>1);
/*%
$$ = dispatch3(def, $2, $5, $6);
@@ -3022,6 +3035,7 @@ primary : literal
NODE *body = remove_begin($8);
reduce_nodes(&body);
$$ = NEW_DEFS($2, $5, $7, body);
+ set_line_body(body, $<num>1);
nd_set_line($$, $<num>1);
/*%
$$ = dispatch5(defs, $2, $3, $5, $7, $8);
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 18e7d8f87c..78a7ab8c90 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -980,6 +980,19 @@ x = __ENCODING__
end;
end
+ def test_method_location_in_rescue
+ bug = '[ruby-core:79388] [Bug #13181]'
+ obj, line = Object.new, __LINE__+1
+ def obj.location
+ #
+ raise
+ rescue
+ caller_locations(1, 1)[0]
+ end
+
+ assert_equal(line, obj.location.lineno, bug)
+ end
+
=begin
def test_past_scope_variable
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
diff --git a/version.h b/version.h
index 606d03178a..3ac3ed843d 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.4.3"
-#define RUBY_RELEASE_DATE "2017-10-11"
-#define RUBY_PATCHLEVEL 201
+#define RUBY_RELEASE_DATE "2017-11-03"
+#define RUBY_PATCHLEVEL 202
#define RUBY_RELEASE_YEAR 2017
-#define RUBY_RELEASE_MONTH 10
-#define RUBY_RELEASE_DAY 11
+#define RUBY_RELEASE_MONTH 11
+#define RUBY_RELEASE_DAY 3
#include "ruby/version.h"