Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 1749 Creating anonymous record based on a function call with a list arg fails #2096

Merged
merged 6 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Fantomas.Tests.MultilineBlockBracketsOnSameColumnRecordTests
open NUnit.Framework
open FsUnit
open Fantomas.Tests.TestHelper
open Fantomas.FormatConfig

let config =
{ config with
Expand Down Expand Up @@ -1189,3 +1190,42 @@ let ``anonymous records with comments on record fields`` () =
BarValue = barValue
|}
"""

[<Test>]
let ``creating anonymous record based on a function call, 1749`` () =
formatSourceString
false
"""
type Foo = static member Create a = {| Name = "Isaac" |}
type Bar() = member _.Create (a,b) = ()
let bar = Bar()
type Thing = static member Stuff = 123
let x = {| Foo.Create ([ bar.Create(Thing.Stuff, Thing.Stuff) ]) with Age = 41 |}
"""
{ config with
ArrayOrListMultilineFormatter = MultilineFormatterType.CharacterWidth
SpaceBeforeUppercaseInvocation = true }
|> prepend newline
|> should
equal
"""
type Foo =
static member Create a = {| Name = "Isaac" |}

type Bar() =
member _.Create(a, b) = ()

let bar = Bar ()

type Thing =
static member Stuff = 123

let x =
{| Foo.Create (
[
bar.Create (Thing.Stuff, Thing.Stuff)
]
) with
Age = 41
|}
"""
2 changes: 1 addition & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3099,7 +3099,7 @@ and genMultilineAnonRecordAlignBrackets (isStruct: bool) fields copyInfo astCont
let fieldsExpr = col sepSemiNln fields (genAnonRecordFieldName astContext)

let copyExpr fieldsExpr e =
genExpr astContext e
atCurrentColumnIndent (genExpr astContext e)
+> (!- " with"
+> indent
+> whenShortIndent indent
Expand Down