Fantomas collapses a multi-line record expression to a single line when it fits within the line length limit. When a non-last field has a fun lambda value, this produces invalid F# code because the fun keyword's body extends to the end of the expression, swallowing subsequent fields.
Issue created from fantomas-online
Code
type Rec = {
A : int
B : int -> int
C : int
}
let test () : Rec =
{
A = 1
B = fun x -> x + 1
C = 3
}
Result
type Rec = { A: int; B: int -> int; C: int }
let test () : Rec =
{ A = 1
B =
fun x ->
x + 1
C = 3 }
Problem description
F# parses fun x -> as extending to the end of the enclosing expression. The semicolons become sequential expressions inside the lambda body:
{ A = 1; B = fun x -> (x + 1; C = 3) }
Suggested fix (I have a PR ready)
Keep the single-line format but wrap the lambda in parentheses to delimit the body:
let test () : Rec = { A = 1; B = (fun x -> x + 1); C = 3 }
Extra information
Reproduced on version 7.0.3 and 8.0.0-alpha-003.
Options
Fantomas main branch at 1/1/1990
Default Fantomas configuration
Fantomas collapses a multi-line record expression to a single line when it fits within the line length limit. When a non-last field has a fun lambda value, this produces invalid F# code because the fun keyword's body extends to the end of the expression, swallowing subsequent fields.
Issue created from fantomas-online
Code
Result
Problem description
F# parses
fun x ->as extending to the end of the enclosing expression. The semicolons become sequential expressions inside the lambda body:Suggested fix (I have a PR ready)
Keep the single-line format but wrap the lambda in parentheses to delimit the body:
Extra information
Reproduced on version
7.0.3and8.0.0-alpha-003.Options
Fantomas main branch at 1/1/1990
Default Fantomas configuration