diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MethodResolution/StaticMethodResolution.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MethodResolution/StaticMethodResolution.fs index c6602a0f1be..ab27213cdbf 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MethodResolution/StaticMethodResolution.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MethodResolution/StaticMethodResolution.fs @@ -5,37 +5,68 @@ namespace Conformance.BasicGrammarElements open FSharp.Test.Compiler open Xunit +// Regression tests for https://github.com/dotnet/fsharp/issues/19664 +// Fix: https://github.com/dotnet/fsharp/pull/19698 module StaticMethodResolution = - - // Regression test for https://github.com/dotnet/fsharp/issues/19664 - // - // When a static extension method is defined in a *different* [] module than - // the generic type it extends, and shares its name with an intrinsic static member, - // resolving the call via the explicit-type-argument syntax `Type.Member(...)` - // previously failed with FS0505. The non-generic dotted form `Type.Member(...)` - // resolved correctly, so any regression test that omits the explicit type arguments - // does not actually exercise the bug. See the discussion at - // https://github.com/dotnet/fsharp/issues/19675#issuecomment-4373059900. - [] - let ``Static extension on generic type resolves with explicit type arguments``() = - Fsx """ -module Extensions = + + let private sharedSource = """ +module Lib = type StaticGeneric<'T> = static member Bar() = () static member Bar(_: int, _: int) = () [] - module StaticGenericExtensions = + module Extensions = type StaticGeneric<'T> with static member Bar(_: int) = () +""" + + [] + let ``Static extension on generic type resolves with explicit type arguments``() = + Fsx (sharedSource + """ +module Program = + open Lib + + StaticGeneric.Bar() + StaticGeneric.Bar(42) // extension overload — regressed to FS0505 in issue #19664 + StaticGeneric.Bar(42, 0) + """) + |> typecheck + |> shouldSucceed + + [] + let ``Static extension on generic type - wrong arity produces diagnostic``() = + Fsx (sharedSource + """ +module Program = + open Lib + + StaticGeneric.Bar(1, 2, 3) + """) + |> typecheck + |> shouldFail + |> withErrorCode 505 + + [] + let ``Static extension on generic type resolves alongside instance members``() = + Fsx """ +module Lib = + + type Container<'T> = + static member Create() = Unchecked.defaultof> + member _.Value = Unchecked.defaultof<'T> + + [] + module Extensions = + type Container<'T> with + static member Create(_: 'T) = Unchecked.defaultof> module Program = - open Extensions + open Lib - StaticGeneric.Bar() // intrinsic, 0 args - StaticGeneric.Bar(42) // regressed: extension, 1 arg, see issue 19664 (FS0505) - StaticGeneric.Bar(42, 0) // intrinsic, 2 args + let c = Container.Create() + let c2 = Container.Create(42) + let v = c.Value """ |> typecheck - |> shouldSucceed \ No newline at end of file + |> shouldSucceed