From b910496974ad349aac444ca9cefd0f96dc1490d7 Mon Sep 17 00:00:00 2001 From: dawe Date: Tue, 9 Nov 2021 22:34:41 +0100 Subject: [PATCH 1/2] Fix 1954: val mutable in signature loses 'mutable' --- src/Fantomas.Tests/SignatureTests.fs | 18 ++++++++++++++++++ src/Fantomas/CodePrinter.fs | 5 +++-- src/Fantomas/SourceParser.fs | 4 ++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Fantomas.Tests/SignatureTests.fs b/src/Fantomas.Tests/SignatureTests.fs index 8f1ee43040..4094f5f933 100644 --- a/src/Fantomas.Tests/SignatureTests.fs +++ b/src/Fantomas.Tests/SignatureTests.fs @@ -171,6 +171,24 @@ module Tainted val GetHashCodeTainted: (Tainted<'T> -> int) when 'T: equality """ +[] +let ``should keep mutable in type signature`` () = + formatSourceString + true + """ +module Tainted +val mutable showParserStackOnParseError: bool +""" + config + |> prepend newline + |> should + equal + """ +module Tainted + +val mutable showParserStackOnParseError: bool +""" + [] let ``should keep access modifiers in signatures seperated`` () = formatSourceString diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index b41aee054e..d5c18d0289 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -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) @@ -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) @@ -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 = diff --git a/src/Fantomas/SourceParser.fs b/src/Fantomas/SourceParser.fs index d0cef9fb47..e6457ec90b 100644 --- a/src/Fantomas/SourceParser.fs +++ b/src/Fantomas/SourceParser.fs @@ -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 From 7ab04773a89c850bcb24eaa63485629ddda029a9 Mon Sep 17 00:00:00 2001 From: dawe Date: Tue, 9 Nov 2021 22:56:02 +0100 Subject: [PATCH 2/2] Add issue number to test name --- src/Fantomas.Tests/SignatureTests.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fantomas.Tests/SignatureTests.fs b/src/Fantomas.Tests/SignatureTests.fs index 4094f5f933..bc645c0182 100644 --- a/src/Fantomas.Tests/SignatureTests.fs +++ b/src/Fantomas.Tests/SignatureTests.fs @@ -172,7 +172,7 @@ val GetHashCodeTainted: (Tainted<'T> -> int) when 'T: equality """ [] -let ``should keep mutable in type signature`` () = +let ``should keep mutable in type signature, 1954`` () = formatSourceString true """