From 41326b78d559aeca355f9df928a6f6c0733337de Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 27 Sep 2024 09:25:43 +0200 Subject: [PATCH 1/2] respect generic arity in method uniqueness --- src/Compiler/AbstractIL/il.fs | 1 + .../FSharpScriptTests.fs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Compiler/AbstractIL/il.fs b/src/Compiler/AbstractIL/il.fs index b10a119fced..3c70f5eb93f 100644 --- a/src/Compiler/AbstractIL/il.fs +++ b/src/Compiler/AbstractIL/il.fs @@ -5700,6 +5700,7 @@ let resolveILMethodRefWithRescope r (td: ILTypeDef) (mref: ILMethodRef) = mref.CallingConv = md.CallingConv && (md.Parameters, argTypes) ||> List.lengthsEqAndForall2 (fun p1 p2 -> r p1.Type = p2) + && md.GenericParams.Length = mref.GenericArity && // REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct r md.Return.Type = retType) diff --git a/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs b/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs index 50c354da629..a8739d93390 100644 --- a/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs +++ b/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs @@ -486,3 +486,17 @@ test pfloat "1.234" let opt = script.Eval(code) |> getValue let value = opt.Value Assert.True(true = downcast value.ReflectionValue) + + [] + member _.``Nuget package with method duplicates differing only in generic arity``() = + // regression test for: https://github.com/dotnet/fsharp/issues/17796 + // Was an internal error + let code = """ +#r "nuget: Microsoft.Extensions.DependencyInjection.Abstractions" +open Microsoft.Extensions.DependencyInjection +let add (col:IServiceCollection) = + col.AddSingleton() +""" + use script = new FSharpScript(additionalArgs=[| |]) + let _value,diag = script.Eval(code) + Assert.Empty(diag) From 38e4a4f459a6d14652ef29edc4d42d24d7de513e Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 27 Sep 2024 10:07:29 +0200 Subject: [PATCH 2/2] notes --- docs/release-notes/.FSharp.Compiler.Service/9.0.200.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index 5ef93105656..aff2e0484b9 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -1,5 +1,6 @@ ### Fixed +* Fix internal error when calling 'AddSingleton' and other overloads only differing in generic arity ([PR #17804](https://github.com/dotnet/fsharp/pull/17804)) ### Added