Skip to content

Commit

Permalink
Merge pull request #414 from jindraivanek/issue-326
Browse files Browse the repository at this point in the history
Fix 326
  • Loading branch information
jindraivanek authored Feb 15, 2019
2 parents 1702f29 + b7684c5 commit 7af96a4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
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

0 comments on commit 7af96a4

Please sign in to comment.