Skip to content

Commit 46b2600

Browse files
authored
Merge pull request #3225 from nojaf/fix-3043
Fix multiline function type in parens causing compiler error
2 parents c73ba5d + 9dcd108 commit 46b2600

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Lambda closing parenthesis in chained method calls is no longer placed on its own line when `MultiLineLambdaClosingNewline` is enabled. [#2553](https://github.com/fsprojects/fantomas/issues/2553)
99
- Long `&` (AND) patterns now break across multiple lines to respect max line length. [#1780](https://github.com/fsprojects/fantomas/issues/1780)
1010
- Empty array with trivia inside now has correct indentation in Stroustrup style. [#3098](https://github.com/fsprojects/fantomas/issues/3098)
11+
- Multiline function type inside parentheses gets extra indentation to avoid compiler error. [#3043](https://github.com/fsprojects/fantomas/issues/3043)
1112

1213
## [8.0.0-alpha-002] - 2025-12-15
1314

src/Fantomas.Core.Tests/TypeAnnotationTests.fs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ type CancellableTaskResultBuilderBase with
130130
task: CancellationToken -> ^TaskLike,
131131
continuation:
132132
('TResult1
133-
-> CancellableTaskResultCode<'TOverall, 'Error, 'TResult2>)
133+
-> CancellableTaskResultCode<
134+
'TOverall,
135+
'Error,
136+
'TResult2
137+
>)
134138
) : bool =
135139
true
136140
"""
@@ -580,3 +584,31 @@ XYZ.app<
580584
wouldSomeoneWriteThisCode
581585
}]
582586
"""
587+
588+
[<Test>]
589+
let ``multiline function type in parens gets extra indent, 3043`` () =
590+
formatSourceString
591+
"""
592+
type MyCustomTypeWithAPrettyLongDescribingName = MyCustomConstructor1
593+
594+
let private myFunction
595+
: string
596+
-> (MyCustomTypeWithAPrettyLongDescribingName -> MyCustomTypeWithAPrettyLongDescribingName -> MyCustomTypeWithAPrettyLongDescribingName)
597+
-> unit =
598+
fun a fn -> ()
599+
"""
600+
config
601+
|> prepend newline
602+
|> should
603+
equal
604+
"""
605+
type MyCustomTypeWithAPrettyLongDescribingName = MyCustomConstructor1
606+
607+
let private myFunction
608+
: string
609+
-> (MyCustomTypeWithAPrettyLongDescribingName
610+
-> MyCustomTypeWithAPrettyLongDescribingName
611+
-> MyCustomTypeWithAPrettyLongDescribingName)
612+
-> unit =
613+
fun a fn -> ()
614+
"""

src/Fantomas.Core/CodePrinter.fs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3275,10 +3275,26 @@ let genType (t: Type) =
32753275
genNode node (isSmallExpression size smallExpression longExpression) ctx
32763276

32773277
| Type.Paren node ->
3278-
genSingleTextNode node.OpeningParen
3279-
+> genType node.Type
3280-
+> genSingleTextNode node.ClosingParen
3281-
|> genNode node
3278+
match node.Type with
3279+
| Type.Funs _ ->
3280+
let short =
3281+
genSingleTextNode node.OpeningParen
3282+
+> genType node.Type
3283+
+> genSingleTextNode node.ClosingParen
3284+
3285+
let long =
3286+
genSingleTextNode node.OpeningParen
3287+
+> indent
3288+
+> genType node.Type
3289+
+> unindent
3290+
+> genSingleTextNode node.ClosingParen
3291+
3292+
expressionFitsOnRestOfLine short long |> genNode node
3293+
| _ ->
3294+
genSingleTextNode node.OpeningParen
3295+
+> genType node.Type
3296+
+> genSingleTextNode node.ClosingParen
3297+
|> genNode node
32823298
| Type.SignatureParameter node ->
32833299
genOnelinerAttributes node.Attributes
32843300
+> optSingle (fun id -> genSingleTextNode id +> sepColon) node.Identifier

0 commit comments

Comments
 (0)