Skip to content

Commit

Permalink
Preserve override keyword in read property. (#2261)
Browse files Browse the repository at this point in the history
Fixes #2221.
  • Loading branch information
nojaf authored May 16, 2022
1 parent d053c38 commit 9703198
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
* Idempotency problem with ParsedHashDirective in signature file. [#2258](https://github.com/fsprojects/fantomas/issues/2258)
* Keyword 'override' gets changed to 'member'. [#2221](https://github.com/fsprojects/fantomas/issues/2221)

## [5.0.0-alpha-007] - 2022-05-16

Expand Down
74 changes: 74 additions & 0 deletions src/Fantomas.Core.Tests/ClassTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,3 +1073,77 @@ type Foo() =
and set (value) = // comment set
myInternalValue <- value
"""

[<Test>]
let ``preserve override keyword in read property, 2221`` () =
formatSourceString
false
"""
type StreamHelper() =
inherit Stream()
override x.ReadAsync (dst, offset, count, tok) =
()
override x.WriteAsync (dst, offset, count, tok) =
()
override x.Flush () = ()
override x.Seek(offset:int64, origin:SeekOrigin) =
()
override x.SetLength(value:int64) =
()
override x.Read(dst, offset, count) =
()
override x.Write(src, offset, count) =
()
override x.ReadByte() =
()
override x.WriteByte item =
()
override x.CanRead
with get() =
true
override x.CanSeek
with get() =
false
override x.CanWrite
with get() =
true
override x.Length
with get() =
1
override x.Position
with get() =
1
and set value =
1
override x.Dispose disposing =
()
"""
config
|> prepend newline
|> should
equal
"""
type StreamHelper() =
inherit Stream()
override x.ReadAsync(dst, offset, count, tok) = ()
override x.WriteAsync(dst, offset, count, tok) = ()
override x.Flush() = ()
override x.Seek(offset: int64, origin: SeekOrigin) = ()
override x.SetLength(value: int64) = ()
override x.Read(dst, offset, count) = ()
override x.Write(src, offset, count) = ()
override x.ReadByte() = ()
override x.WriteByte item = ()
override x.CanRead = true
override x.CanSeek = false
override x.CanWrite = true
override x.Length = 1
override x.Position
with get () = 1
and set value = 1
override x.Dispose disposing = ()
"""
5 changes: 1 addition & 4 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -894,10 +894,7 @@ and genMemberBinding astContext b =
)
| _ -> p

let prefix =
(onlyIfNot mf.IsInstance (!- "static ")
+> !- "member ")

let prefix = genMemberFlags mf
genMemberBindingImpl astContext prefix ats px ao isInline pat equalsRange e synValInfo
| _ ->
let ps = List.map snd ps
Expand Down

0 comments on commit 9703198

Please sign in to comment.