summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2025-01-11 15:38:41 -0500
committerKevin Newton <[email protected]>2025-01-11 19:09:05 -0500
commit117d6e145a0270ab8fc9134403519ef13b9ebb24 (patch)
tree9a263ddc529dc4b661d1a636387c38551d53444c /lib
parent9c962ea7926e06a57a738bd1e0232ccf09e32771 (diff)
[ruby/prism] Fix `not` receiver
`not foo` should be `!foo` `not()` should be `!nil` Fixes [Bug #21027] https://github.com/ruby/prism/commit/871ed4b462
Diffstat (limited to 'lib')
-rw-r--r--lib/prism/translation/ripper.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb
index 018842715b..dce96e01ab 100644
--- a/lib/prism/translation/ripper.rb
+++ b/lib/prism/translation/ripper.rb
@@ -1045,10 +1045,20 @@ module Prism
bounds(node.location)
on_unary(node.name, receiver)
when :!
- receiver = visit(node.receiver)
+ if node.message == "not"
+ receiver =
+ if !node.receiver.is_a?(ParenthesesNode) || !node.receiver.body.nil?
+ visit(node.receiver)
+ end
- bounds(node.location)
- on_unary(node.message == "not" ? :not : :!, receiver)
+ bounds(node.location)
+ on_unary(:not, receiver)
+ else
+ receiver = visit(node.receiver)
+
+ bounds(node.location)
+ on_unary(:!, receiver)
+ end
when *BINARY_OPERATORS
receiver = visit(node.receiver)
value = visit(node.arguments.arguments.first)