From 77d05bb16c8c3672151b8f8265ba1fe8e91b425d Mon Sep 17 00:00:00 2001 From: Vlad Zarytovskii Date: Thu, 24 Aug 2023 15:59:23 +0200 Subject: [PATCH] Backport #15845 to 17.7 (#15848) Co-authored-by: Florian Verdonck Co-authored-by: Tomas Grosup --- eng/Versions.props | 2 +- global.json | 2 +- src/Compiler/Checking/CheckDeclarations.fs | 6 ++- .../ConstraintSolver/MemberConstraints.fs | 28 ++++++++++++ .../member-contrains-type-extension.fsx | 23 ++++++++++ .../Signatures/TypeTests.fs | 43 +++++++++++++++++++ 6 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/member-contrains-type-extension.fsx diff --git a/eng/Versions.props b/eng/Versions.props index cf4599795e..10e2b39f2a 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -15,7 +15,7 @@ 7 0 - 400 + 401 0 diff --git a/global.json b/global.json index 69c511874c..c4eab6a46d 100644 --- a/global.json +++ b/global.json @@ -15,7 +15,7 @@ "xcopy-msbuild": "17.6.0-2" }, "native-tools": { - "perl": "5.32.1.1" + "perl": "5.38.0.1" }, "msbuild-sdks": { "Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.23320.3", diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index dcd34ee74d..49300a9fcd 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -3958,8 +3958,10 @@ module TcDeclarations = if tcref.TyparsNoRange.Length = synTypars.Length then (tcref.TyparsNoRange, synTypars) ||> List.zip - |> List.iter (fun (typar, SynTyparDecl.SynTyparDecl(_, SynTypar(ident = untypedIdent))) -> - typar.SetIdent(untypedIdent) + |> List.iter (fun (typar, SynTyparDecl.SynTyparDecl (_, tp)) -> + let (SynTypar(ident = untypedIdent; staticReq = sr)) = tp + if typar.StaticReq = sr then + typar.SetIdent(untypedIdent) ) res diff --git a/tests/FSharp.Compiler.ComponentTests/ConstraintSolver/MemberConstraints.fs b/tests/FSharp.Compiler.ComponentTests/ConstraintSolver/MemberConstraints.fs index 08544356d6..3bb1770b41 100644 --- a/tests/FSharp.Compiler.ComponentTests/ConstraintSolver/MemberConstraints.fs +++ b/tests/FSharp.Compiler.ComponentTests/ConstraintSolver/MemberConstraints.fs @@ -46,3 +46,31 @@ else () |> run |> shouldSucceed |> withExitCode 0 + + [] + let ``Respect nowarn 957 for extension method`` () = + FSharp """ +module Foo + +type DataItem<'data> = + { Identifier: string + Label: string + Data: 'data } + + static member Create<'data>(identifier: string, label: string, data: 'data) = + { DataItem.Identifier = identifier + DataItem.Label = label + DataItem.Data = data } + +#nowarn "957" + +type DataItem< ^input> with + + static member inline Create(item: ^input) = + let stringValue: string = (^input: (member get_StringValue: unit -> string) (item)) + let friendlyStringValue: string = (^input: (member get_FriendlyStringValue: unit -> string) (item)) + + DataItem.Create< ^input>(stringValue, friendlyStringValue, item) +""" + |> compile + |> shouldSucceed diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/member-contrains-type-extension.fsx b/tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/member-contrains-type-extension.fsx new file mode 100644 index 0000000000..e60a8a5a66 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/member-contrains-type-extension.fsx @@ -0,0 +1,23 @@ +module Extensions + +type DataItem<'data> = + { Identifier: string + Label: string + Data: 'data } + + static member Create<'data>(identifier: string, label: string, data: 'data) = + { DataItem.Identifier = identifier + DataItem.Label = label + DataItem.Data = data } + +#nowarn "957" + +type DataItem< ^input> with + + static member inline Create(item: ^input) = + let stringValue: string = (^input: (member get_StringValue: unit -> string) (item)) + + let friendlyStringValue: string = + (^input: (member get_FriendlyStringValue: unit -> string) (item)) + + DataItem.Create< ^input>(stringValue, friendlyStringValue, item) \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs index cd63744950..291c794133 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs @@ -133,6 +133,49 @@ type System.Collections.Concurrent.ConcurrentDictionary<'key,'value> with member TryFind: key: 'key -> 'value option""" +[] +let ``Don't update typar name in type extension when TyparStaticReq doesn't match`` () = + FSharp """ +module Extensions + +type DataItem<'data> = + { Identifier: string + Label: string + Data: 'data } + + static member Create<'data>(identifier: string, label: string, data: 'data) = + { DataItem.Identifier = identifier + DataItem.Label = label + DataItem.Data = data } + +#nowarn "957" + +type DataItem< ^input> with + + static member inline Create(item: ^input) = + let stringValue: string = (^input: (member get_StringValue: unit -> string) (item)) + + let friendlyStringValue: string = + (^input: (member get_FriendlyStringValue: unit -> string) (item)) + + DataItem.Create< ^input>(stringValue, friendlyStringValue, item) +""" + |> printSignatures + |> should equal + """ +module Extensions + +type DataItem<'data> = + { + Identifier: string + Label: string + Data: 'data + } + + static member inline Create: item: ^input -> DataItem<^input> when ^input: (member get_StringValue: unit -> string) and ^input: (member get_FriendlyStringValue: unit -> string) + + static member Create<'data> : identifier: string * label: string * data: 'data -> DataItem<'data>""" + [] let ``ValText for C# abstract member override`` () = let csharp = CSharp """