From 99a07652fbf5d2cd97d0a1e90ec0c78ac4385d77 Mon Sep 17 00:00:00 2001 From: jindraivanek Date: Thu, 14 Feb 2019 10:21:36 +0100 Subject: [PATCH 1/2] tests --- src/Fantomas.Tests/RecordTests.fs | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Fantomas.Tests/RecordTests.fs b/src/Fantomas.Tests/RecordTests.fs index 433beadbfe..18b48d5585 100644 --- a/src/Fantomas.Tests/RecordTests.fs +++ b/src/Fantomas.Tests/RecordTests.fs @@ -223,4 +223,38 @@ type MyExc = type MyExc = inherit Exception new(msg) = { inherit Exception(msg) } +""" + +[] +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 } +""" + +[] +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 } """ \ No newline at end of file From b7e224b72b42ef987a25e84978fb71ac1b7a3284 Mon Sep 17 00:00:00 2001 From: jindraivanek Date: Thu, 14 Feb 2019 10:23:08 +0100 Subject: [PATCH 2/2] fix #326 --- src/Fantomas/CodePrinter.fs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 52abca5558..0db712f575 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -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) ->