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

Add extra space when first type argument is a statically resolved type parameter #13825

Closed
wants to merge 1 commit 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
17 changes: 14 additions & 3 deletions src/Compiler/Checking/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -862,11 +862,22 @@ module PrintTypes =

/// Layout type arguments, either NAME<ty, ..., ty> or (ty, ..., ty) NAME *)
and layoutTypeAppWithInfoAndPrec denv env tcL prec prefix argTys =
if prefix then
if prefix then
let addExtraSpace argTy =
match argTy with
| TType_var(typar, _) when typar.StaticReq = TyparStaticReq.HeadType -> SepL.space
| _ -> emptyL

match argTys with
| [] -> tcL
| [argTy] -> tcL ^^ sepL (tagPunctuation "<") ^^ (layoutTypeWithInfoAndPrec denv env 4 argTy) ^^ rightL (tagPunctuation">")
| _ -> bracketIfL (prec <= 1) (tcL ^^ angleL (layoutTypesWithInfoAndPrec denv env 2 (sepL (tagPunctuation ",")) argTys))
| [argTy] ->
tcL
^^ sepL (tagPunctuation "<")
^^ addExtraSpace argTy
^^ (layoutTypeWithInfoAndPrec denv env 4 argTy)
^^ rightL (tagPunctuation">")
| firstArgTy :: _ ->
bracketIfL (prec <= 1) (tcL ^^ angleL (addExtraSpace firstArgTy ^^ layoutTypesWithInfoAndPrec denv env 2 (sepL (tagPunctuation ",")) argTys))
else
match argTys with
| [] -> tcL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
<Compile Include="Signatures\TestHelpers.fs" />
<Compile Include="Signatures\ModuleOrNamespaceTests.fs" />
<Compile Include="Signatures\RecordTests.fs" />
<Compile Include="Signatures\StaticallyResolvedTypeParameterTests.fs" />
</ItemGroup>
<ItemGroup>
<Content Include="resources\**" CopyToOutputDirectory="Never" CopyToPublishDirectory="PreserveNewest" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type PullActions =
Log : int
}
"""
|> printSignaturesWith 80
|> printSignaturesWithPageWidth 80
|> should
equal
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module FSharp.Compiler.ComponentTests.Signatures.StaticallyResolvedTypeParameterTests

open Xunit
open FsUnit
open FSharp.Test.Compiler
open FSharp.Compiler.ComponentTests.Signatures.TestHelpers

[<Fact>]
let ``Generic function with constraint`` () =
FSharp
"""
module MyApp.GoodStuff

let inline toString< ^revision when ^revision: (static member GetCommitHash: ^revision -> string)>
(p: System.Threading.Tasks.Task< ^revision >)
: string =
""
"""
|> printSignaturesWithPageWidth 80
|> should
equal
"""
module MyApp.GoodStuff

val inline toString:
p: System.Threading.Tasks.Task< ^revision> -> string
when ^revision: (static member GetCommitHash: ^revision -> string)"""

[<Fact>]
let ``Multiple constraints parameters in type definition`` () =
FSharp
"""
module Foo

type Meh<'g, 'f> =
class
end

let inline toString< ^revision>
(p: Meh< ^revision, ^revision>)
: string =
""
"""
|> printSignaturesWithPageWidth 80
|> should
equal
"""
module Foo

type Meh<'g,'f> =
class end

val inline toString: p: Meh< ^revision,^revision> -> string"""
2 changes: 1 addition & 1 deletion tests/FSharp.Test.Utilities/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,4 +1342,4 @@ module rec Compiler =
|> String.concat "\n"

let printSignatures cUnit = printSignaturesImpl None cUnit
let printSignaturesWith pageWidth cUnit = printSignaturesImpl (Some pageWidth) cUnit
let printSignaturesWithPageWidth pageWidth cUnit = printSignaturesImpl (Some pageWidth) cUnit