Skip to content

Remove invalid check for named arguments. #1380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/Fantomas.Tests/IfThenElseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,3 +1738,40 @@ let private tryGetUrlWithExactMatch
else
None
"""

[<Test>]
let ``infix equals expression in if condition expression, 1241`` () =
formatSourceString
false
"""
namespace SomeNamespace

module SomeModule =

let SomeFunc () =
let someLocalFunc someVeryLooooooooooooooooooooooooooooooooooooooooooooooooongParam =
async {
if (someVeryLooooooooooooooooooooooooooooooooooooooooooooooooongParam = 1) then
return failwith "xxx"
}
()

"""
config
|> prepend newline
|> should
equal
"""
namespace SomeNamespace

module SomeModule =

let SomeFunc () =
let someLocalFunc someVeryLooooooooooooooooooooooooooooooooooooooooooooooooongParam =
async {
if (someVeryLooooooooooooooooooooooooooooooooooooooooooooooooongParam = 1) then
return failwith "xxx"
}

()
"""
9 changes: 7 additions & 2 deletions src/Fantomas.Tests/SynExprNewTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let ``single multi line named argument instance`` () =
false
"""
let myInstance =
new EvilBadRequest(Content = new StringContent("File was too way too large",
new EvilBadRequest(Content = new StringContent("File was too way too large, as in waaaaaaaaaaaaaaaaaaaay tooooooooo long",
System.Text.Encoding.UTF16,
"application/text"))
"""
Expand All @@ -45,7 +45,12 @@ let myInstance =
"""
let myInstance =
new EvilBadRequest(
Content = new StringContent("File was too way too large", System.Text.Encoding.UTF16, "application/text")
Content =
new StringContent(
"File was too way too large, as in waaaaaaaaaaaaaaaaaaaay tooooooooo long",
System.Text.Encoding.UTF16,
"application/text"
)
)
"""

Expand Down
15 changes: 10 additions & 5 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,14 +1267,23 @@ and genExpr astContext synExpr ctx =
+> col sepComma args (genExpr astContext)
+> sepCloseTFor rpr

let genExprLong astContext e =
let expr e =
match e with
| InfixApp (equal, operatorExpr, e1, e2) when (equal = "=") ->
genNamedArgumentExpr astContext operatorExpr e1 e2
| _ -> genExpr astContext e

expr e

let long =
!- "new "
+> genType astContext false t
+> sepSpace
+> sepOpenTFor lpr
+> indent
+> sepNln
+> col (sepComma +> sepNln) args (genExpr astContext)
+> col (sepCommaFixed +> sepNln) args (genExprLong astContext)
+> unindent
+> sepNln
+> sepCloseTFor rpr
Expand Down Expand Up @@ -1640,10 +1649,6 @@ and genExpr astContext synExpr ctx =
+> indentIfNeeded sepNone
)
+> sepCloseTFor rpr
| InfixApp (equal, operatorExpr, e1, e2) when (equal = "=") ->
sepOpenTFor lpr
+> genNamedArgumentExpr astContext operatorExpr e1 e2
+> sepCloseTFor rpr
| LetOrUses _ ->
sepOpenTFor lpr
+> atCurrentColumn (genExpr astContext e)
Expand Down