Skip to content

Commit

Permalink
Add or remove () when necessary. Should fix fsprojects#369
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Nov 28, 2018
1 parent 203eb7e commit 8bf7b8b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Fantomas.Tests/DynamicOperatorTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Fantomas.Tests.DynamicOperatorTests

open NUnit.Framework
open FsUnit
open Fantomas.Tests.TestHelper

[<Test>]
let ``Keep () when dynamic operator is used``() =
formatSourceString false "let memoEquals x = x?(k + 1)" config
|> should equal """let memoEquals x = x?(k + 1)
"""

[<Test>]
let ``Remove () when dynamic operator is string``() =
formatSourceString false "let memoEquals x = x?(k)" config
|> should equal """let memoEquals x = x?k
"""
1 change: 1 addition & 0 deletions src/Fantomas.Tests/Fantomas.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<Compile Include="NoTrailingSpacesTests.fs" />
<Compile Include="LazyTests.fs" />
<Compile Include="LongIdentWithDotsTests.fs" />
<Compile Include="DynamicOperatorTests.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fantomas\Fantomas.fsproj" />
Expand Down
9 changes: 8 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,14 @@ and genExpr astContext synExpr =
!- s +> sepSpace +> sepOpenS +> genExpr { astContext with IsNakedRange = true } e
+> ifElse (checkBreakForExpr e) (sepNln +> sepCloseSFixed) sepCloseS
// This supposes to be an infix function, but for some reason it isn't picked up by InfixApps
| App(Var "?", e::es) -> genExpr astContext e -- "?" +> col sepSpace es (genExpr astContext)
| App(Var "?", e::es) ->
match es with
| SynExpr.Ident(_)::_
| SynExpr.Const(SynConst.String(_,_),_)::_ ->
genExpr astContext e -- "?" +> col sepSpace es (genExpr astContext)
| _ ->
genExpr astContext e -- "?" +> sepOpenT +> col sepSpace es (genExpr astContext) +> sepCloseT

| App(Var "..", [e1; e2]) ->
let expr = genExpr astContext e1 -- ".." +> genExpr astContext e2
ifElse astContext.IsNakedRange expr (sepOpenS +> expr +> sepCloseS)
Expand Down

0 comments on commit 8bf7b8b

Please sign in to comment.