From fd07ac3620a1911fdfbb0dffe29c8c4866a943aa Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 9 Jun 2023 09:40:29 +0200 Subject: [PATCH 1/4] Wrap hash postfix type in parentheses. --- src/Compiler/Checking/NicePrint.fs | 9 ++++++++- .../Signatures/SigGenerationRoundTripTests.fs | 2 +- .../hash_constraint_seq.fsx | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/hash_constraint_seq.fsx diff --git a/src/Compiler/Checking/NicePrint.fs b/src/Compiler/Checking/NicePrint.fs index 7f0779c062e..b1795630f6f 100644 --- a/src/Compiler/Checking/NicePrint.fs +++ b/src/Compiler/Checking/NicePrint.fs @@ -708,7 +708,14 @@ module PrintTypes = match Zmap.tryFind typar env.inplaceConstraints with | Some typarConstraintTy -> if Zset.contains typar env.singletons then - leftL (tagPunctuation "#") ^^ layoutTypeWithInfo denv env typarConstraintTy + let tyLayout = + match typarConstraintTy with + | TType_app (tyconRef = tc) when not (usePrefix denv tc) -> + layoutTypeWithInfo denv env typarConstraintTy + |> bracketL + | _ -> layoutTypeWithInfo denv env typarConstraintTy + + leftL (tagPunctuation "#") ^^ tyLayout else (varL ^^ sepL (tagPunctuation ":>") ^^ layoutTypeWithInfo denv env typarConstraintTy) |> bracketL diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/SigGenerationRoundTripTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/SigGenerationRoundTripTests.fs index 0b4be741d50..ffccf696996 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/SigGenerationRoundTripTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/SigGenerationRoundTripTests.fs @@ -28,7 +28,7 @@ let ``Generate and compile`` implFileName = |> withLangVersionPreview |> withDefines ["TESTS_AS_APP";"COMPILED"] |> ignoreWarnings + |> withOptions [ "--warnaserror:64" ] |> asExe |> compile |> shouldSucceed - diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/hash_constraint_seq.fsx b/tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/hash_constraint_seq.fsx new file mode 100644 index 00000000000..60bdb225ade --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/hash_constraint_seq.fsx @@ -0,0 +1,7 @@ +module Foo + +open System +open System.Threading.Tasks + +let mapWithAdditionalDependenies + (mapping: 'a -> 'b * #seq<#IDisposable>) = 0 From 474a5181bab280d4b8e6f6b552b6a8a6a65d36d8 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 9 Jun 2023 11:13:23 +0200 Subject: [PATCH 2/4] Only add parentheses if there are any typeInstantiations. --- src/Compiler/Checking/NicePrint.fs | 3 +- .../FSharp.Compiler.ComponentTests.fsproj | 1 + .../Signatures/HashConstraintTests.fs | 33 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Signatures/HashConstraintTests.fs diff --git a/src/Compiler/Checking/NicePrint.fs b/src/Compiler/Checking/NicePrint.fs index b1795630f6f..da4caaf7f2e 100644 --- a/src/Compiler/Checking/NicePrint.fs +++ b/src/Compiler/Checking/NicePrint.fs @@ -710,7 +710,8 @@ module PrintTypes = if Zset.contains typar env.singletons then let tyLayout = match typarConstraintTy with - | TType_app (tyconRef = tc) when not (usePrefix denv tc) -> + | TType_app (tyconRef = tc; typeInstantiation = ti) + when ti.Length > 0 && not (usePrefix denv tc) -> layoutTypeWithInfo denv env typarConstraintTy |> bracketL | _ -> layoutTypeWithInfo denv env typarConstraintTy diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 82efbccafab..4a84103ebbc 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -250,6 +250,7 @@ + diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/HashConstraintTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/HashConstraintTests.fs new file mode 100644 index 00000000000..733facb9680 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/HashConstraintTests.fs @@ -0,0 +1,33 @@ +module FSharp.Compiler.ComponentTests.Signatures.HashConstraintTests + +open Xunit +open FsUnit +open FSharp.Test.Compiler +open FSharp.Compiler.ComponentTests.Signatures.TestHelpers + +[] +let ``Optional hash constraint`` () = + FSharp + """ +module Foo + +[] +type Node = + abstract Children: int array + +let noa<'n when 'n :> Node> (n: 'n option) = + match n with + | None -> Array.empty + | Some n -> [| n :> Node |] +""" + |> printSignatures + |> should + equal + """ +module Foo + +type Node = + + abstract Children: int array + +val noa: n: #Node option -> Node array""" From 94936fb5c5d0b4a59a565b888e26396db2b570e4 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 9 Jun 2023 17:10:17 +0200 Subject: [PATCH 3/4] Trigger CI From e6a7326ba332452b1f7640c2a8ae9d1024149e15 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 9 Jun 2023 19:52:51 +0200 Subject: [PATCH 4/4] Update module names. --- tests/FSharp.Compiler.ComponentTests/Signatures/ArrayTests.fs | 2 +- .../Signatures/HashConstraintTests.fs | 4 ++-- .../Signatures/MissingDiagnostic.fs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/ArrayTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/ArrayTests.fs index 7d74903c4eb..74a69d7e703 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/ArrayTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/ArrayTests.fs @@ -1,4 +1,4 @@ -module Signatures.SignatureTests +module Signatures.ArrayTests open Xunit open Signatures.TestHelpers diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/HashConstraintTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/HashConstraintTests.fs index 733facb9680..beb33a8bac5 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/HashConstraintTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/HashConstraintTests.fs @@ -1,9 +1,9 @@ -module FSharp.Compiler.ComponentTests.Signatures.HashConstraintTests +module Signatures.HashConstraintTests open Xunit open FsUnit open FSharp.Test.Compiler -open FSharp.Compiler.ComponentTests.Signatures.TestHelpers +open Signatures.TestHelpers [] let ``Optional hash constraint`` () = diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/MissingDiagnostic.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/MissingDiagnostic.fs index 2d263fa728f..55181649b03 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/MissingDiagnostic.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/MissingDiagnostic.fs @@ -1,4 +1,4 @@ -module FSharp.Compiler.ComponentTests.Signatures.MissingDiagnostic +module Signatures.MissingDiagnostic open Xunit open FSharp.Test