From 4e841c405554d019814cae8927cc87fde8f4e44f Mon Sep 17 00:00:00 2001 From: dawe Date: Wed, 10 Nov 2021 15:42:22 +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 b9eed23bc2..5c683b1eab 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, 1954`` () = + 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 b7870f753f..a11012a516 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -867,7 +867,7 @@ and genMemberFlagsForMemberBinding astContext (mf: MemberFlags) (rangeOfBindingA |> Option.defaultValue (!- "override ") <| ctx -and genVal astContext (Val (ats, px, ao, s, identRange, t, vi, isInline, _, eo) as node) = +and genVal astContext (Val (ats, px, ao, s, identRange, t, vi, isInline, isMutable, _, eo) as node) = let range, synValTyparDecls = match node with | ValSpfn (_, _, synValTyparDecls, _, _, _, _, _, _, _, range) -> range, synValTyparDecls @@ -883,6 +883,7 @@ and genVal astContext (Val (ats, px, ao, s, identRange, t, vi, isInline, _, eo) +> genAttributes astContext ats +> (!- "val " +> onlyIf isInline (!- "inline ") + +> onlyIf isMutable (!- "mutable ") +> opt sepSpace ao genAccess -- s +> genericParams @@ -4045,7 +4046,7 @@ and genMemberSig astContext node = | SynMemberSig.NestedType (_, r) -> r, SynMemberSig_NestedType match node with - | MSMember (Val (ats, px, ao, s, _, t, vi, isInline, ValTyparDecls (tds, _, tcs), eo), mf) -> + | MSMember (Val (ats, px, ao, s, _, t, vi, isInline, _, ValTyparDecls (tds, _, tcs), eo), mf) -> let (FunType namedArgs) = (t, vi) let isFunctionProperty = diff --git a/src/Fantomas/SourceParser.fs b/src/Fantomas/SourceParser.fs index 3a29e4af27..1be8c46c95 100644 --- a/src/Fantomas/SourceParser.fs +++ b/src/Fantomas/SourceParser.fs @@ -1510,9 +1510,9 @@ let (|MSMember|MSInterface|MSInherit|MSValField|MSNestedType|) = | SynMemberSig.NestedType (tds, _) -> MSNestedType tds let (|Val|) - (ValSpfn (ats, (IdentOrKeyword (OpNameFullInPattern (s, _)) as ident), tds, t, vi, isInline, _, px, ao, eo, _)) + (ValSpfn (ats, (IdentOrKeyword (OpNameFullInPattern (s, _)) as ident), tds, t, vi, isInline, isMutable, px, ao, eo, _)) = - (ats, px, ao, s, ident.idRange, t, vi, isInline, tds, eo) + (ats, px, ao, s, ident.idRange, t, vi, isInline, isMutable, tds, eo) // Misc From 2eb43b91564914283db50a742fd8ddb505fd2838 Mon Sep 17 00:00:00 2001 From: dawe Date: Wed, 10 Nov 2021 15:52:15 +0100 Subject: [PATCH 2/2] Fix formatting of (|Val|) --- src/Fantomas/SourceParser.fs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Fantomas/SourceParser.fs b/src/Fantomas/SourceParser.fs index 1be8c46c95..6fd51bee08 100644 --- a/src/Fantomas/SourceParser.fs +++ b/src/Fantomas/SourceParser.fs @@ -1510,7 +1510,17 @@ let (|MSMember|MSInterface|MSInherit|MSValField|MSNestedType|) = | SynMemberSig.NestedType (tds, _) -> MSNestedType tds let (|Val|) - (ValSpfn (ats, (IdentOrKeyword (OpNameFullInPattern (s, _)) as ident), tds, t, vi, isInline, isMutable, px, ao, eo, _)) + (ValSpfn (ats, + (IdentOrKeyword (OpNameFullInPattern (s, _)) as ident), + tds, + t, + vi, + isInline, + isMutable, + px, + ao, + eo, + _)) = (ats, px, ao, s, ident.idRange, t, vi, isInline, isMutable, tds, eo)