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 326 #414

Merged
merged 3 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
34 changes: 34 additions & 0 deletions src/Fantomas.Tests/RecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,38 @@ type MyExc =
type MyExc =
inherit Exception
new(msg) = { inherit Exception(msg) }
"""

[<Test>]
let ``should preserve inherit parts in records with field``() =
formatSourceString false """
type MyExc =
inherit Exception
new(msg) = {inherit Exception(msg)
X = 1}
""" config
|> prepend newline
|> should equal """
type MyExc =
inherit Exception
new(msg) = { inherit Exception(msg); X = 1 }
"""

[<Test>]
let ``should preserve inherit parts in records multiline``() =
formatSourceString false """
type MyExc =
inherit Exception
new(msg) = {inherit Exception(msg)
X = 1
Y = 2}
""" config
|> prepend newline
|> should equal """
type MyExc =
inherit Exception
new(msg) =
{ inherit Exception(msg)
X = 1
Y = 2 }
"""
7 changes: 4 additions & 3 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,11 @@ and genExpr astContext synExpr =
(sepOpenL +> atCurrentColumn (colAutoNlnSkip0 sepWithPreserveEndOfLine xs (genExpr astContext)) +> sepCloseL)

| Record(inheritOpt, xs, eo) ->
let recordExpr = opt (!- " with ") eo (genExpr astContext) +> atCurrentColumn (col sepSemiNln xs (genRecordFieldName astContext))
sepOpenS
+> opt (if xs.IsEmpty then sepNone else sepSemi) inheritOpt
(fun (typ, expr) -> !- "inherit " +> genType astContext false typ +> genExpr astContext expr)
+> opt (!- " with ") eo (genExpr astContext) +> atCurrentColumn (col sepSemiNln xs (genRecordFieldName astContext))
+> atCurrentColumn (opt (if xs.IsEmpty then sepNone else ifElseCtx (futureNlnCheck recordExpr sepNone) sepNln sepSemi) inheritOpt
(fun (typ, expr) -> !- "inherit " +> genType astContext false typ +> genExpr astContext expr))
+> recordExpr
+> sepCloseS

| ObjExpr(t, eio, bd, ims, range) ->
Expand Down