Skip to content

Commit 7e16ba4

Browse files
viralpraxismarcandre
authored andcommitted
Fix flip-flop operator possible children nodes count
One of the "flip-flop"'s operator nodes might be `nil`: ```bash $ ruby-parse --34 -e '!(...(a == 1))' (send (begin (eflipflop nil (begin (send (send nil :a) :== (int 1))))) :!) ``` ```bash $ docker run -it --rm rubylang/all-ruby env ALL_RUBY_SINCE=ruby-2.7.0 ./all-ruby -e '!(..(a==1))' ruby-2.7.0 ... ruby-3.4.1 ```
1 parent f78c17e commit 7e16ba4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/rubocop/ast/traversal.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ def children_count_check_code(range)
118118
many_node_children = %i[dstr dsym xstr regexp array hash pair
119119
mlhs masgn or_asgn and_asgn rasgn mrasgn
120120
undef alias args super yield or and
121-
while_post until_post iflipflop eflipflop
121+
while_post until_post
122122
match_with_lvasgn begin kwbegin return
123123
in_match match_alt break next
124124
match_as array_pattern array_pattern_with_tail
125125
hash_pattern const_pattern find_pattern
126126
index indexasgn procarg0 kwargs]
127127
many_opt_node_children = %i[case rescue resbody ensure for when
128128
case_match in_pattern irange erange
129-
match_pattern match_pattern_p]
129+
match_pattern match_pattern_p iflipflop eflipflop]
130130

131131
### Callbacks for above
132132
def_callback no_children

spec/rubocop/ast/fixtures/code_examples.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,18 @@ class A < B
11481148
#----
11491149
if foo...bar; end
11501150

1151+
#----
1152+
!(...bar)
1153+
1154+
#----
1155+
!(..bar)
1156+
1157+
#----
1158+
!(bar...)
1159+
1160+
#----
1161+
!(bar..)
1162+
11511163
#----
11521164
!(foo...bar)
11531165

0 commit comments

Comments
 (0)