Skip to content

Commit

Permalink
Add space before parameters passed to inherited class. Fixes #720 (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Mar 14, 2020
1 parent c0faf0d commit 25c9126
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/Fantomas.Tests/ClassTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,36 @@ type A =
[<Emit("b")>]
abstract b: Unit -> string
"""

[<Test>]
let ``string parameter to inherited class, 720`` () =
formatSourceString false """type Child() =
inherit Parent ""
""" config
|> prepend newline
|> should equal """
type Child() =
inherit Parent ""
"""

[<Test>]
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
"""

[<Test>]
let ``unit parameter to inherited class`` () =
formatSourceString false """type Child() =
inherit Parent ()
""" config
|> prepend newline
|> should equal """
type Child() =
inherit Parent()
"""
8 changes: 7 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down

0 comments on commit 25c9126

Please sign in to comment.