Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit aa219ef

Browse files
committed
Disallow conditionals with not without parentheses in the predicate from turning into a ternary.
1 parent a0bb8da commit aa219ef

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1313
### Changed
1414

1515
- Correct the pattern for checking if a dynamic symbol can be converted into a label as a hash key.
16+
- Disallow conditionals with `not` without parentheses in the predicate from turning into a ternary.
1617

1718
## [2.4.1] - 2022-05-10
1819

lib/syntax_tree/node.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5115,7 +5115,9 @@ def call(q, node)
51155115
else
51165116
# Otherwise, we're going to check the conditional for certain cases.
51175117
case node
5118-
in predicate: Assign | Command | CommandCall | MAssign | Not | OpAssign
5118+
in predicate: Assign | Command | CommandCall | MAssign | OpAssign
5119+
false
5120+
in predicate: Not[parentheses: false]
51195121
false
51205122
in {
51215123
statements: { body: [truthy] },

test/fixtures/if.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@
4141
else
4242
c
4343
end
44+
%
45+
if not(a)
46+
b
47+
else
48+
c
49+
end
50+
-
51+
not(a) ? b : c

0 commit comments

Comments
 (0)