diff --git a/src/Fantomas.Tests/Fantomas.Tests.fsproj b/src/Fantomas.Tests/Fantomas.Tests.fsproj index 13231ce5b5..afb8146c50 100644 --- a/src/Fantomas.Tests/Fantomas.Tests.fsproj +++ b/src/Fantomas.Tests/Fantomas.Tests.fsproj @@ -1,4 +1,4 @@ - + 2.9.1 FS0988 @@ -44,6 +44,7 @@ + diff --git a/src/Fantomas.Tests/FormattingPropertyTests.fs b/src/Fantomas.Tests/FormattingPropertyTests.fs index 6174fa38fd..2c5df1b86e 100644 --- a/src/Fantomas.Tests/FormattingPropertyTests.fs +++ b/src/Fantomas.Tests/FormattingPropertyTests.fs @@ -366,6 +366,7 @@ let rec shrinkSynExpr = function | SynExpr.DotIndexedGet(expr, _, _, _) | SynExpr.DotGet(expr, _, _, _) | SynExpr.DotSet(expr, _, _, _) + | SynExpr.Set(expr, _, _) | SynExpr.TypeTest(expr, _, _) | SynExpr.Upcast(expr, _, _) | SynExpr.Downcast(expr, _, _) diff --git a/src/Fantomas.Tests/SynExprSetTests.fs b/src/Fantomas.Tests/SynExprSetTests.fs new file mode 100644 index 0000000000..7b533569fe --- /dev/null +++ b/src/Fantomas.Tests/SynExprSetTests.fs @@ -0,0 +1,46 @@ +module Fantomas.Tests.SynExprSetTests + +open NUnit.Framework +open FsUnit +open Fantomas.Tests.TestHelper + +/// See https://github.com/fsharp/fsharp/blob/master/src/fsharp/ast.fs#L633 +/// F# syntax: expr <- expr +/// | Set of SynExpr * SynExpr * range:range + +[] +let ``array indexer set`` () = + formatSourceString false """ +let arr = [|0|] +(arr.[0]) <- 1 +""" config + |> should equal """let arr = [| 0 |] + +(arr.[0]) <- 1 +""" + +[] +let ``setter of type set`` () = + formatSourceString false """ +type T() = + member val X = 0 with get, set +(T().X) <- 1 +""" config + |> prepend newline + |> should equal """ +type T() = + member val X = 0 with get, set + +(T().X) <- 1 +""" + +[] +let ``mutable value set`` () = + formatSourceString false """ +let mutable x = 0 +(x) <- 1 +""" config + |> should equal """let mutable x = 0 + +(x) <- 1 +""" diff --git a/src/Fantomas/CodeFormatterImpl.fs b/src/Fantomas/CodeFormatterImpl.fs index e3302b0421..3106a14dde 100644 --- a/src/Fantomas/CodeFormatterImpl.fs +++ b/src/Fantomas/CodeFormatterImpl.fs @@ -233,7 +233,8 @@ let isValidAST ast = | SynExpr.DotGet(synExpr, _dotm, _longIdent, _range) -> validateExpr synExpr - | SynExpr.DotSet(synExpr1, _longIdent, synExpr2, _range) -> + | SynExpr.DotSet(synExpr1, _, synExpr2, _) + | SynExpr.Set (synExpr1, synExpr2, _) -> List.forall validateExpr [synExpr1; synExpr2] | SynExpr.DotIndexedGet(synExpr, IndexerArgList synExprList, _range, _range2) -> diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index fb111a6637..e7d4cd966e 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -101,7 +101,8 @@ and genSigModuleOrNamespace astContext (SigModuleOrNamespace(ats, px, ao, s, mds +> opt sepSpace ao genAccess -- s +> rep 2 sepNln) +> genSigModuleDeclList astContext mds -and genModuleDeclList astContext = function +and genModuleDeclList astContext e = + match e with | [x] -> genModuleDecl astContext x | OpenL(xs, ys) -> @@ -713,6 +714,10 @@ and genExpr astContext synExpr = let exprF = genExpr { astContext with IsInsideDotGet = true } addParenIfAutoNln e exprF -- (sprintf ".%s" s) | DotSet(e1, s, e2) -> addParenIfAutoNln e1 (genExpr astContext) -- sprintf ".%s <- " s +> genExpr astContext e2 + + | SynExpr.Set(e1,e2, _) -> + addParenIfAutoNln e1 (genExpr astContext) -- sprintf " <- " +> genExpr astContext e2 + | LetOrUseBang(isUse, p, e1, e2) -> atCurrentColumn (ifElse isUse (!- "use! ") (!- "let! ") +> genPat astContext p -- " = " +> genExpr astContext e1 +> sepNln +> genExpr astContext e2)