summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-30 14:38:15 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-30 14:38:15 +0000
commitd69b1e3b305a79659f4686f3cffc5c03c18ea832 (patch)
tree2d25d5356f6a5680daf45022d7156fbc4f96efa4 /parse.y
parent9ad02399920e67053063b122f10e9973c50d6ed8 (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_3@60947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y20
1 files changed, 17 insertions, 3 deletions
diff --git a/parse.y b/parse.y
index 8774014a6b..aba64e6920 100644
--- a/parse.y
+++ b/parse.y
@@ -389,6 +389,17 @@ static int parser_yyerror(struct parser_params*, const char*);
static int yylex(YYSTYPE*, struct parser_params*);
+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);
+ }
+}
+
#ifndef RIPPER
#define yyparse ruby_yyparse
@@ -2688,9 +2699,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);
@@ -2975,6 +2984,7 @@ primary : literal
{
/*%%%*/
$$ = NEW_CLASS($2, $5, $3);
+ set_line_body($5, $<num>4);
nd_set_line($$, $<num>4);
/*%
$$ = dispatch3(class, $2, $3, $5);
@@ -2994,6 +3004,7 @@ primary : literal
{
/*%%%*/
$$ = NEW_SCLASS($3, $6);
+ set_line_body($6, nd_line($3));
fixpos($$, $3);
/*%
$$ = dispatch2(sclass, $3, $6);
@@ -3017,6 +3028,7 @@ primary : literal
{
/*%%%*/
$$ = NEW_MODULE($2, $4);
+ set_line_body($4, $<num>3);
nd_set_line($$, $<num>3);
/*%
$$ = dispatch2(module, $2, $4);
@@ -3041,6 +3053,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);
@@ -3066,6 +3079,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);