Skip to content

Commit

Permalink
Fix power operator in code quotation pattern match (#1952)
Browse files Browse the repository at this point in the history
* #1945 regression test

* Adapt (|OpNameFullInPattern|) special handling of
star operators. When the space is removed it becomes
a nested comment breaking code

* Use standard template

* Remove blank line and put source on next line.

Co-authored-by: nojaf <florian.verdonck@outlook.com>
  • Loading branch information
cgravill and nojaf committed Nov 6, 2021
1 parent 10f599c commit c8f06c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/Fantomas.Tests/ActivePatternTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,19 @@ let (|ParseRegex|_|) regex str =
else
None
"""

[<Test>]
let ``ensure spacing around power operator, 1945`` () =
formatSourceString
false
"""
match expr with
| SpecificCall <@@ ( ** ) @@> (_, _, [ s1; s2 ]) -> ()"""
config
|> prepend newline
|> should
equal
"""
match expr with
| SpecificCall <@@ ( ** ) @@> (_, _, [ s1; s2 ]) -> ()
"""
6 changes: 5 additions & 1 deletion src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ let (|OpNameFull|) (x: Identifier) =
|| IsPrefixOperator s
|| IsTernaryOperator s
|| s = "op_Dynamic" then
s'
/// Use two spaces for symmetry
if String.startsWithOrdinal "*" s' && s' <> "*" then
sprintf " %s " s'
else
s'
else
match x with
| Id (Ident s)
Expand Down

0 comments on commit c8f06c1

Please sign in to comment.