From aa219efdb41eb9f2508bd8beb0bb4b6182b6c1da Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 13 May 2022 21:42:07 -0400 Subject: [PATCH] Disallow conditionals with `not` without parentheses in the predicate from turning into a ternary. --- CHANGELOG.md | 1 + lib/syntax_tree/node.rb | 4 +++- test/fixtures/if.rb | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81c1d0fc..ed3100f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Changed - Correct the pattern for checking if a dynamic symbol can be converted into a label as a hash key. +- Disallow conditionals with `not` without parentheses in the predicate from turning into a ternary. ## [2.4.1] - 2022-05-10 diff --git a/lib/syntax_tree/node.rb b/lib/syntax_tree/node.rb index 2f0d9419..7667378d 100644 --- a/lib/syntax_tree/node.rb +++ b/lib/syntax_tree/node.rb @@ -5115,7 +5115,9 @@ def call(q, node) else # Otherwise, we're going to check the conditional for certain cases. case node - in predicate: Assign | Command | CommandCall | MAssign | Not | OpAssign + in predicate: Assign | Command | CommandCall | MAssign | OpAssign + false + in predicate: Not[parentheses: false] false in { statements: { body: [truthy] }, diff --git a/test/fixtures/if.rb b/test/fixtures/if.rb index 607af05d..9045e5bf 100644 --- a/test/fixtures/if.rb +++ b/test/fixtures/if.rb @@ -41,3 +41,11 @@ else c end +% +if not(a) + b +else + c +end +- +not(a) ? b : c