Skip to content
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

Fix 1954: Don't lose 'mutable' in val signature #1967

Closed
wants to merge 2 commits into from
Closed
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
18 changes: 18 additions & 0 deletions src/Fantomas.Tests/SignatureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ module Tainted
val GetHashCodeTainted: (Tainted<'T> -> int) when 'T: equality
"""

[<Test>]
let ``should keep mutable in type signature, 1954`` () =
formatSourceString
true
"""
module Tainted
val mutable showParserStackOnParseError: bool
"""
config
|> prepend newline
|> should
equal
"""
module Tainted

val mutable showParserStackOnParseError: bool
"""

[<Test>]
let ``should keep access modifiers in signatures seperated`` () =
formatSourceString
Expand Down
5 changes: 3 additions & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ and genMemberFlagsForMemberBinding astContext (mf: SynMemberFlags) (rangeOfBindi
|> Option.defaultValue (!- "override ")
<| ctx

and genVal astContext (Val (ats, px, ao, s, identRange, t, vi, isInline, tds, eo, range)) =
and genVal astContext (Val (ats, px, ao, s, identRange, t, vi, isInline, isMutable, tds, eo, range)) =
let typeName = genTypeAndParam astContext s tds []

let (FunType namedArgs) = (t, vi)
Expand All @@ -933,6 +933,7 @@ and genVal astContext (Val (ats, px, ao, s, identRange, t, vi, isInline, tds, eo
+> genAttributes astContext ats
+> (!- "val "
+> onlyIf isInline (!- "inline ")
+> onlyIf isMutable (!- "mutable ")
+> opt sepSpace ao genAccess
+> typeName
|> genTriviaFor Ident_ identRange)
Expand Down Expand Up @@ -4195,7 +4196,7 @@ and genMemberSig astContext node =
| SynMemberSig.NestedType (_, r) -> r, SynMemberSig_NestedType

match node with
| MSMember (Val (ats, px, ao, s, _, t, vi, isInline, tds, eo, _), mf) ->
| MSMember (Val (ats, px, ao, s, _, t, vi, isInline, _, tds, eo, _), mf) ->
let (FunType namedArgs) = (t, vi)

let isFunctionProperty =
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1565,13 +1565,13 @@ let (|Val|)
t,
vi,
isInline,
_,
isMutable,
px,
ao,
eo,
range))
=
(ats, px, ao, s, ident.idRange, t, vi, isInline, typars, eo, range)
(ats, px, ao, s, ident.idRange, t, vi, isInline, isMutable, typars, eo, range)

// Misc

Expand Down