From 5bdbee96e479f714c7f9b6b98f012268cbd9051b Mon Sep 17 00:00:00 2001 From: "NARUSE, Yui" Date: Fri, 13 Mar 2020 21:43:44 +0900 Subject: Squashed commit of the following: [Backport #16516] commit c98c492578d898dc07a04b8240d8d5b1508ffafa Author: Nobuyoshi Nakada Date: Fri Jan 17 16:56:53 2020 +0900 Added test for f38b3e8c707ebdcad05aa9485cf1760640b74fbb commit f38b3e8c707ebdcad05aa9485cf1760640b74fbb Author: Nobuyoshi Nakada Date: Thu Jan 16 18:34:31 2020 +0900 Fixed the location of args node with numbered parameter --- parse.y | 6 +++++- test/ruby/test_ast.rb | 9 ++++++++- test/ruby/test_syntax.rb | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/parse.y b/parse.y index 1281eb6258..16c464e49e 100644 --- a/parse.y +++ b/parse.y @@ -11377,7 +11377,11 @@ static NODE * args_with_numbered(struct parser_params *p, NODE *args, int max_numparam) { if (max_numparam > NO_PARAM) { - if (!args) args = new_args_tail(p, 0, 0, 0, 0); + if (!args) { + YYLTYPE loc = RUBY_INIT_YYLLOC(); + args = new_args_tail(p, 0, 0, 0, 0); + nd_set_loc(args, &loc); + } args->nd_ainfo->pre_args_num = max_numparam; } return args; diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index 4c156650b8..147d05eadf 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -42,10 +42,11 @@ class TestAst < Test::Unit::TestCase class Helper attr_reader :errors - def initialize(path) + def initialize(path, src: nil) @path = path @errors = [] @debug = false + @ast = RubyVM::AbstractSyntaxTree.parse(src) if src end def validate_range @@ -312,4 +313,10 @@ class TestAst < Test::Unit::TestCase assert_equal(false, kwrest.call('**nil')) assert_equal([:a], kwrest.call('**a')) end + + def test_ranges_numbered_parameter + helper = Helper.new(__FILE__, src: "1.times {_1}") + helper.validate_range + assert_equal([], helper.errors) + end end diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 72f539068d..21b0bc7ce7 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1451,6 +1451,8 @@ eom assert_valid_syntax("->{#{c};->{_1};end;_1}\n") assert_valid_syntax("->{_1;#{c};->{_1};end}\n") end + + 1.times {_1} end def test_value_expr_in_condition -- cgit v1.2.3