Repro steps
- Create the following F# program:
open System
type Foo() = class end
[<EntryPoint>]
let main _ =
let foo = Foo()
let span = Span<int>.Empty
foo.CopyTo(span)
- Try to compile it for
netcoreapp3.1 target framework
Expected behavior
Compiler should tell me that the method in question (Foo.CopyTo(Span)) doesn't exist.
Actual behavior
Compiler reports the following:
Program.fs(7,3): error FS0041: No overloads match for method 'CopyTo'.
Known type of argument: Span<int>
Available overloads:
- (extension) Foo.CopyTo<'T>(destination: Memory<'T>) : unit
- (extension) Foo.CopyTo<'T>(destination: Span<'T>) : unit
Well, it somewhat does tell me that the method doesn't exists, but it uses a very confusing notation: how's an overload Foo.CopyTo<'T> available? And if it does, then why doesn't it get used here?
I suspect that the compiler actually picks a pair of corresponding System.MemoryExtensions.CopyTo methods which are only available for T[]?, but renders them in a confusing way.
Consider how confusing it was when I've tried to call it on BitArray (which has its own CopyTo method which doesn't work for Spans). I was first fascinated to know that BitArray.CopyTo<'T>(destination: Span<'T>) exists, but then very confused on how to call it.
Known workarounds
No.
Related information
Provide any related information (optional):
- Operating system: Windows 10
- .NET Runtime kind:
$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.302
Commit: 41faccf259
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.302\
Host (useful for support):
Version: 3.1.6
Commit: 3acd9b0cd1
.NET Core SDKs installed:
2.1.808 [C:\Program Files\dotnet\sdk]
2.2.207 [C:\Program Files\dotnet\sdk]
3.1.302 [C:\Program Files\dotnet\sdk]
- Editing Tools: initially I've noticed the same confusing text in Rider
Repro steps
netcoreapp3.1target frameworkExpected behavior
Compiler should tell me that the method in question (
Foo.CopyTo(Span)) doesn't exist.Actual behavior
Compiler reports the following:
Well, it somewhat does tell me that the method doesn't exists, but it uses a very confusing notation: how's an overload
Foo.CopyTo<'T>available? And if it does, then why doesn't it get used here?I suspect that the compiler actually picks a pair of corresponding
System.MemoryExtensions.CopyTomethods which are only available forT[]?, but renders them in a confusing way.Consider how confusing it was when I've tried to call it on
BitArray(which has its ownCopyTomethod which doesn't work for Spans). I was first fascinated to know thatBitArray.CopyTo<'T>(destination: Span<'T>)exists, but then very confused on how to call it.Known workarounds
No.
Related information
Provide any related information (optional):