From 25c9126844f1d0d85e323f118b15c866cf145554 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Sat, 14 Mar 2020 11:10:11 +0100 Subject: [PATCH] Add space before parameters passed to inherited class. Fixes #720 (#723) --- src/Fantomas.Tests/ClassTests.fs | 33 ++++++++++++++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 8 +++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Fantomas.Tests/ClassTests.fs b/src/Fantomas.Tests/ClassTests.fs index edd868405e..c926c526ad 100644 --- a/src/Fantomas.Tests/ClassTests.fs +++ b/src/Fantomas.Tests/ClassTests.fs @@ -465,3 +465,36 @@ type A = [] abstract b: Unit -> string """ + +[] +let ``string parameter to inherited class, 720`` () = + formatSourceString false """type Child() = + inherit Parent "" +""" config + |> prepend newline + |> should equal """ +type Child() = + inherit Parent "" +""" + +[] +let ``float parameter to inherited class`` () = + formatSourceString false """type Child() = + inherit Parent 7.9 +""" config + |> prepend newline + |> should equal """ +type Child() = + inherit Parent 7.9 +""" + +[] +let ``unit parameter to inherited class`` () = + formatSourceString false """type Child() = + inherit Parent () +""" config + |> prepend newline + |> should equal """ +type Child() = + inherit Parent() +""" \ No newline at end of file diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index f545b42c31..752a4e3458 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -2112,7 +2112,13 @@ and genMemberDefn astContext node = | MDNestedType _ -> invalidArg "md" "This is not implemented in F# compiler" | MDOpen(s) -> !- (sprintf "open %s" s) // What is the role of so - | MDImplicitInherit(t, e, _) -> !- "inherit " +> genType astContext false t +> genExpr astContext e + | MDImplicitInherit(t, e, _) -> + let addSpaceAfterType = + match e with + | SynExpr.Const(SynConst.Unit, _) -> false + | SynExpr.Const(_, _) -> true // string, numbers, ... + | _ -> false + !- "inherit " +> genType astContext false t +> ifElse addSpaceAfterType sepSpace sepNone +> genExpr astContext e | MDInherit(t, _) -> !- "inherit " +> genType astContext false t | MDValField f -> genField astContext "val " f | MDImplicitCtor(ats, ao, ps, so) ->