dotnet / dotnet/fsharp

Fail to resolve to non generic overload.

Open
#1,647 10 comments 0 reactions 0 assignees View on GitHub
Feature Improvement Needs-RFC Resolution-By Design
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

The F# compiler fails to decide which overload to select, in this scenario and according to the spec it should prefer the non-generic method.

Not only fails to follow the F# spec, it also fails to apply the general .NET rule (not sure if it's written somewhere). The same in C# compiles fine and works as expected.
#### Repro steps

Try this code:
1. Step A

Send this to the F# interactive:

```
module Test =
type C =
static member M<'T>(x:'T ) = printfn "1"; x : 'T
static member M<'T>(x:seq<'T>) = printfn "2"; x : seq<'T>
```
1. Step B

Now try this:

```
let x = Test.C.M(10)
let y = Test.C.M(seq [1..10])
```
#### Expected behavior

The expected behavior is to print 1, then 2 and return the input values.

If you compile Step A to a dll, reference it from C# and try:

```
var x = Test.C.M(10);
var y = Test.C.M(Enumerable.Range(1,10));
```

it compiles, print 1 and then 2 as expected.
#### Actual behavior

It fails to compile with the following error:

```
let y = Test.C.M(seq [1..10]);;
--------^^^^^^^^^^^^^^^^^^^^^
>
stdin(4,9): error FS0041: A unique overload for method 'M' could not be determined based on type information prior to this program point. A type annotation may be needed. Candidates: static member Test.C.M : x:'T -> 'T, static member Test.C.M : x:seq<'T> -> seq<'T>
```
#### Known workarounds

No known workarounds.
#### Related information
- Operating system: All
- Branch : since the very first F# version up to the current master version.
- .NET Runtime, CoreCLR or Mono Version: N/A
- Editing Tools (e.g. Visual Studio Version): N/A
- Links to F# RFCs or entries on http://fslang.uservoice.com: N/A
- Links to performance testing scripts: N/A
- Indications of severity: Medium to High

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.