Skip to content

Commit a9774ea

Browse files
authored
Merge pull request #3303 from nojaf/revisit-lambdas
Revisit lambdas
2 parents 7d206bf + 600d1b7 commit a9774ea

File tree

9 files changed

+695
-144
lines changed

9 files changed

+695
-144
lines changed

AGENTS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ All scripts accept a file path or stdin, with optional `--signature` and `--edit
2020

2121
Scripts require a debug build first (`dotnet build src/Fantomas/Fantomas.fsproj`).
2222

23+
## Changelog
24+
25+
When updating `CHANGELOG.md`, add new entries to the **end** of the relevant section (e.g. `### Fixed`), not the top. One entry per issue.
26+
2327
## Post-task Steps
2428

2529
Run these after completing a task, not during iterative development — analyzers can be slow.

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## [Unreleased]
3+
## [8.0.0-alpha-008] - 2026-03-25
44

55
### Added
66

@@ -14,6 +14,9 @@
1414
- `%%` (double-percent) infix operator moved to new line, producing invalid F#. [#2107](https://github.com/fsprojects/fantomas/issues/2107)
1515
- Indentation warning when formatting `match` with long anonymous record discriminant. [#1903](https://github.com/fsprojects/fantomas/issues/1903)
1616
- Index-without-dot with variable key followed by unit arguments added spurious spaces, e.g. `dict[key] () ()` became `dict [ key ] () ()`. [#2519](https://github.com/fsprojects/fantomas/issues/2519)
17+
- Open-ended expressions (lambda, if-then-else, match, ...) in non-last positions of infix, tuple, list/array, and record expressions now stay multiline to preserve semantics. [#3279](https://github.com/fsprojects/fantomas/issues/3279)
18+
- Lambda in tuple in list on single line changes code meaning. [#3278](https://github.com/fsprojects/fantomas/issues/3278)
19+
- Custom operator applied to lambda collapses to single line changing semantics. [#3274](https://github.com/fsprojects/fantomas/issues/3274)
1720

1821
## [8.0.0-alpha-007] - 2026-03-10
1922

src/Fantomas.Core.Tests/ControlStructureTests.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ elif true then ()
417417
"""
418418

419419
[<Test>]
420-
let ``multiline if in tuple`` () =
420+
let ``multiline if in tuple uses comma-leading layout`` () =
421421
formatSourceString
422422
"""
423423
(if true then 1 else 2
@@ -428,7 +428,8 @@ let ``multiline if in tuple`` () =
428428
|> should
429429
equal
430430
"""
431-
((if true then 1 else 2), 3)
431+
(if true then 1 else 2
432+
, 3)
432433
"""
433434

434435
// https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting#formatting-if-expressions

src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
<Compile Include="NullnessTests.fs" />
137137
<Compile Include="AutoPropertiesTests.fs" />
138138
<Compile Include="PrefixTests.fs" />
139+
<Compile Include="RequiresMultilineToPreserveSemanticsTests.fs" />
139140
</ItemGroup>
140141
<ItemGroup>
141142
<ProjectReference Include="..\Fantomas.Core\Fantomas.Core.fsproj" />

src/Fantomas.Core.Tests/LambdaTests.fs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ let dayOfWeekToNum (d: DayOfWeek) =
11731173
"""
11741174

11751175
[<Test>]
1176-
let ``piped lambda with if-then-else, short, 2196`` () =
1176+
let ``piped lambda with if-then-else stays multiline to preserve semantics, 2196`` () =
11771177
formatSourceString
11781178
"""
11791179
let foo () =
@@ -1187,7 +1187,9 @@ let foo () =
11871187
equal
11881188
"""
11891189
let foo () =
1190-
f () |> (fun x -> if x then 1 else 2) |> g
1190+
f ()
1191+
|> fun x -> if x then 1 else 2
1192+
|> g
11911193
"""
11921194

11931195
[<Test>]
@@ -1457,7 +1459,7 @@ f
14571459
"""
14581460

14591461
[<Test>]
1460-
let ``lambda in non-last record field should be parenthesized on single line, 3246`` () =
1462+
let ``lambda in non-last record field stays multiline to preserve semantics, 3246`` () =
14611463
formatSourceString
14621464
"""
14631465
type Rec = {
@@ -1480,5 +1482,10 @@ let test () : Rec =
14801482
"""
14811483
type Rec = { A: int; B: int -> int; C: int }
14821484
1483-
let test () : Rec = { A = 1; B = (fun x -> x + 1); C = 3 }
1485+
let test () : Rec =
1486+
{
1487+
A = 1
1488+
B = fun x -> x + 1
1489+
C = 3
1490+
}
14841491
"""

src/Fantomas.Core.Tests/OperatorTests.fs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ let ( */ ) = (+)
12551255
"""
12561256

12571257
[<Test>]
1258-
let ``piped lambda on a single line`` () =
1258+
let ``piped lambda stays multiline to preserve semantics`` () =
12591259
formatSourceString
12601260
"""
12611261
let a : (unit -> int) list =
@@ -1268,11 +1268,14 @@ let a : (unit -> int) list =
12681268
|> should
12691269
equal
12701270
"""
1271-
let a: (unit -> int) list = (fun () -> failwith "": int) |> List.singleton |> id
1271+
let a: (unit -> int) list =
1272+
fun () -> failwith "": int
1273+
|> List.singleton
1274+
|> id
12721275
"""
12731276

12741277
[<Test>]
1275-
let ``piped tuple on a single line`` () =
1278+
let ``piped tuple stays multiline to preserve semantics`` () =
12761279
formatSourceString
12771280
"""
12781281
fun i -> sprintf "%i" i, fun () -> i
@@ -1284,11 +1287,13 @@ fun i -> sprintf "%i" i, fun () -> i
12841287
|> should
12851288
equal
12861289
"""
1287-
(fun i -> sprintf "%i" i, fun () -> i) |> List.init foo |> Map.ofList
1290+
fun i -> sprintf "%i" i, fun () -> i
1291+
|> List.init foo
1292+
|> Map.ofList
12881293
"""
12891294

12901295
[<Test>]
1291-
let ``lambda piped into non newlineInfixApp`` () =
1296+
let ``lambda piped into non newlineInfixApp stays multiline to preserve semantics`` () =
12921297
formatSourceString
12931298
"""
12941299
fun sum count -> sum / float count
@@ -1300,7 +1305,9 @@ fun sum count -> sum / float count
13001305
|> should
13011306
equal
13021307
"""
1303-
(fun sum count -> sum / float count) <*| sum xs <*| count
1308+
fun sum count -> sum / float count
1309+
<*| sum xs
1310+
<*| count
13041311
"""
13051312

13061313
[<Test>]

0 commit comments

Comments
 (0)