diff --git a/src/Fantomas.Tests/StructTests.fs b/src/Fantomas.Tests/StructTests.fs index d63f52843f..1ca6363119 100644 --- a/src/Fantomas.Tests/StructTests.fs +++ b/src/Fantomas.Tests/StructTests.fs @@ -86,3 +86,23 @@ let t = struct (1, 2) match t with | struct (x, y) -> () """ + +[] +let ``struct tuple type abbreviation, 605`` () = + formatSourceString false "type TupleStruct = (struct (string * string))" config + |> prepend newline + |> should equal """ +type TupleStruct = (struct (string * string)) +""" + +[] +let ``struct tuple type abbreviation, sigfile`` () = + formatSourceString true """namespace meh + +type TupleStruct = (struct (string * string))""" config + |> prepend newline + |> should equal """ +namespace meh + +type TupleStruct = (struct (string * string)) +""" \ No newline at end of file diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 6e256ae6b7..e8c11c2a02 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1570,7 +1570,16 @@ and genTypeDefn astContext (TypeDef(ats, px, ao, tds, tcs, tdr, ms, s, preferPos | Simple TDSRNone -> typeName | Simple(TDSRTypeAbbrev t) -> - let genTypeAbbrev = genType astContext false t + let genTypeAbbrev = + let needsParenthesis = + match t with + | SynType.Tuple(isStruct, typeNames, _) -> + (isStruct && List.length typeNames > 1) + | _ -> false + + ifElse needsParenthesis sepOpenT sepNone +> + genType astContext false t +> + ifElse needsParenthesis sepCloseT sepNone let genMembers = ifElse (List.isEmpty ms) @@ -1698,8 +1707,19 @@ and genSigTypeDefn astContext (SigTypeDef(ats, px, ao, tds, tcs, tdr, ms, s, pre | SigSimple TDSRNone -> typeName - | SigSimple(TDSRTypeAbbrev t) -> - typeName +> sepEq +> sepSpace +> genType astContext false t + | SigSimple(TDSRTypeAbbrev t) -> + let genTypeAbbrev = + let needsParenthesis = + match t with + | SynType.Tuple(isStruct, typeNames, _) -> + (isStruct && List.length typeNames > 1) + | _ -> false + + ifElse needsParenthesis sepOpenT sepNone +> + genType astContext false t +> + ifElse needsParenthesis sepCloseT sepNone + + typeName +> sepEq +> sepSpace +> genTypeAbbrev | SigSimple(TDSRException(ExceptionDefRepr(ats, px, ao, uc))) -> genExceptionBody astContext ats px ao uc