Skip to content

Commit d4e3435

Browse files
authored
Fix missing parentheses around labelled tuple argument (#2811)
1 parent 8df0432 commit d4e3435

7 files changed

Lines changed: 36 additions & 2 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ profile. This started with version 0.26.0.
2121
- Fix lexer error on Windows when an Odoc code block contains CRLF line
2222
endings (@hhugo)
2323

24+
- Fix missing parentheses in `(a, ~b:(if .. then .. else ..))` (#2811, @Julow)
25+
2426
## 0.29.0
2527

2628
### Highlight

lib/Ast.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,9 @@ end = struct
21062106
memo
21072107

21082108
let last_tuple_and_simple f l =
2109-
match List.last_exn l with Lte_simple l -> f l.lte_elt | _ -> false
2109+
match List.last_exn l with
2110+
| Lte_simple {lte_label= None; lte_elt} -> f lte_elt
2111+
| _ -> false
21102112

21112113
(** [exposed cls exp] holds if there is a right-most subexpression of [exp]
21122114
which satisfies [Exp.mem_cls cls] and is not parenthesized. *)

test/passing/refs.ahrefs/labeled_tuples.ml.ref

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,11 @@ module type T = sig
637637
a ->
638638
'b
639639
end
640+
641+
let func cond a b1 b2 = ~a, ~b:(if cond then b1 else b2)
642+
643+
let func cond a b1 b2 =
644+
( a,
645+
~b:(match cond with
646+
| true -> b1
647+
| false -> b2) )

test/passing/refs.default/labeled_tuples.ml.ref

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,3 +576,6 @@ module type T = sig
576576
a ->
577577
'b
578578
end
579+
580+
let func cond a b1 b2 = (~a, ~b:(if cond then b1 else b2))
581+
let func cond a b1 b2 = (a, ~b:(match cond with true -> b1 | false -> b2))

test/passing/refs.janestreet/labeled_tuples.ml.ref

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,3 +636,12 @@ module type T = sig
636636
-> a
637637
-> 'b
638638
end
639+
640+
let func cond a b1 b2 = ~a, ~b:(if cond then b1 else b2)
641+
642+
let func cond a b1 b2 =
643+
( a
644+
, ~b:(match cond with
645+
| true -> b1
646+
| false -> b2) )
647+
;;

test/passing/refs.ocamlformat/labeled_tuples.ml.ref

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,7 @@ module type T = sig
643643
-> a
644644
-> 'b
645645
end
646+
647+
let func cond a b1 b2 = (~a, ~b:(if cond then b1 else b2))
648+
649+
let func cond a b1 b2 = (a, ~b:(match cond with true -> b1 | false -> b2))

test/passing/tests/labeled_tuples.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,4 +664,10 @@ module type T = sig
664664
-> tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
665665
-> a
666666
-> 'b
667-
end
667+
end
668+
669+
let func cond a b1 b2 =
670+
(~a, ~b:(if cond then b1 else b2))
671+
672+
let func cond a b1 b2 =
673+
(a, ~b:(match cond with true -> b1 | false -> b2))

0 commit comments

Comments
 (0)