Skip to content

Commit 05b9468

Browse files
authored
Merge pull request #400 from viralpraxis/fix-not-with-binary-operator-precedence-unparsing
Fix `not` with binary operator unparsing
2 parents 2d19247 + 964230a commit 05b9468

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/unparser/node_helpers.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def n_range?(node)
4040
end
4141

4242
%i[
43+
and
4344
arg
4445
args
4546
array
@@ -67,6 +68,7 @@ def n_range?(node)
6768
lambda
6869
lvar
6970
match_rest
71+
or
7072
pair
7173
rescue
7274
send

lib/unparser/writer/send/unary.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class Unary < self
1212

1313
private_constant(*constants(false))
1414

15-
def dispatch
15+
def dispatch # rubocop:disable Metrics/AbcSize
1616
name = selector
1717
first_child = children.fetch(0)
1818

19-
if n_flipflop?(first_child)
19+
if n_flipflop?(first_child) || n_and?(first_child) || n_or?(first_child)
2020
write 'not '
2121
else
2222
write(MAP.fetch(name, name).to_s)

test/corpus/semantic/not.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
!(foo and bar)
2+
!(foo or bar)
3+
not(foo and bar)
4+
not(foo or bar)
5+
! foo and bar
6+
! foo or bar
7+
not foo and bar
8+
not foo or bar
9+
!(foo && bar)
10+
!(foo || bar)
11+
not(foo && bar)
12+
not(foo || bar)
13+
! foo && bar
14+
! foo || bar
15+
not foo && bar
16+
not foo || bar

0 commit comments

Comments
 (0)