From 4ac8d1172483634bb24183b8ad2aaa03435b17a3 Mon Sep 17 00:00:00 2001 From: Kazuki Tsujimoto Date: Sat, 1 Apr 2023 16:28:05 +0900 Subject: [PATCH] `*` in an array pattern should not be parsed as nil in ripper After 6c0925ba7017efde6091e2ec4f1a6be268166696, it was impossible to distinguish between the presence or absence of `*`. # Before the commit Ripper.sexp('0 in []')[1][0][2][1] #=> [:aryptn, nil, nil, nil, nil] Ripper.sexp('0 in [*]')[1][0][2][1] #=> [:aryptn, nil, nil, [:var_field, nil], nil] # After the commit Ripper.sexp('0 in []')[1][0][2][1] #=> [:aryptn, nil, nil, nil, nil] Ripper.sexp('0 in [*]')[1][0][2][1] #=> [:aryptn, nil, nil, nil, nil] This commit reverts it. --- parse.y | 2 +- test/ripper/test_sexp.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/parse.y b/parse.y index 4ff8644c47..f371185ee0 100644 --- a/parse.y +++ b/parse.y @@ -4656,7 +4656,7 @@ p_rest : tSTAR tIDENTIFIER /*%%%*/ $$ = 0; /*% %*/ - /*% ripper: Qnil %*/ + /*% ripper: var_field(p, Qnil) %*/ } ; diff --git a/test/ripper/test_sexp.rb b/test/ripper/test_sexp.rb index 1bc99b9b97..a1cf5e4f0a 100644 --- a/test/ripper/test_sexp.rb +++ b/test/ripper/test_sexp.rb @@ -229,7 +229,7 @@ eot [__LINE__, %q{ case 0; in *; end }] => [:case, [:@int, "0", [1, 5]], - [:in, [:aryptn, nil, nil, nil, nil], [[:void_stmt]], nil]], + [:in, [:aryptn, nil, nil, [:var_field, nil], nil], [[:void_stmt]], nil]], [__LINE__, %q{ case 0; in *,a; end }] => [:case, @@ -238,7 +238,7 @@ eot [:aryptn, nil, nil, - nil, + [:var_field, nil], [[:var_field, [:@ident, "a", [1, 13]]]]], [[:void_stmt]], nil]], @@ -426,9 +426,9 @@ eot [:in, [:fndptn, nil, - nil, + [:var_field, nil], [[:var_field, [:@ident, "a", [1, 9]]]], - nil], + [:var_field, nil]], nil, nil]],