Skip to content

Commit 490331a

Browse files
committed
not operation should never be parsed as a constant
1 parent 06f67f0 commit 490331a

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

compiler/syntax/src/res_parens.ml

+5-9
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,13 @@ let lazy_or_assert_or_await_expr_rhs ?(in_await = false) expr =
230230
Parenthesized
231231
| _ -> Nothing)
232232

233-
let is_prefixed_constant constant =
234-
let is_prefix txt =
233+
let is_negative_constant constant =
234+
let is_neg txt =
235235
let len = String.length txt in
236-
len > 0
237-
&&
238-
match (String.get [@doesNotRaise]) txt 0 with
239-
| '-' | '~' -> true
240-
| _ -> false
236+
len > 0 && (String.get [@doesNotRaise]) txt 0 = '-'
241237
in
242238
match constant with
243-
| (Parsetree.Pconst_integer (i, _) | Pconst_float (i, _)) when is_prefix i ->
239+
| (Parsetree.Pconst_integer (i, _) | Pconst_float (i, _)) when is_neg i ->
244240
true
245241
| _ -> false
246242

@@ -264,7 +260,7 @@ let field_expr expr =
264260
Pexp_constraint ({pexp_desc = Pexp_pack _}, {ptyp_desc = Ptyp_package _});
265261
} ->
266262
Nothing
267-
| {pexp_desc = Pexp_constant c} when is_prefixed_constant c -> Parenthesized
263+
| {pexp_desc = Pexp_constant c} when is_negative_constant c -> Parenthesized
268264
| {pexp_desc = Pexp_fun _}
269265
when ParsetreeViewer.is_underscore_apply_sugar expr ->
270266
Nothing

0 commit comments

Comments
 (0)