-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collection expressions: prefer ReadOnlySpan<T> over Span<T> in overload resolution #70328
Conversation
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs
Outdated
Show resolved
Hide resolved
…ion/OverloadResolution.cs
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs
Outdated
Show resolved
Hide resolved
…ion/OverloadResolution.cs
static void F1(int[] value) { } | ||
static void F1(object[] value) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember the exact notes but isn't this supposed to be unambiguous just like (int,int,int) and (object,object,object)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not aware of a decision to prefer one array type over another for a collection expression conversion in overload resolution, other than the existing rule to prefer type T1
over T2
if there is an implicit conversion from T1
to T2
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake, I thought most-specific rules can interact with the common-type from elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relevant notes: https://github.com/dotnet/csharplang/blob/main/meetings/2023/LDM-2023-09-20.md
Though that's only a special-case around ref structs to resolve this, and only in one direction.
Diagnostic(ErrorCode.ERR_AmbigCall, "F1").WithArguments("Program.F1(System.ReadOnlySpan<int>)", "Program.F1(System.ReadOnlySpan<object>)").WithLocation(10, 9), | ||
// (11,9): error CS0121: The call is ambiguous between the following methods or properties: 'Program.F2(Span<string>)' and 'Program.F2(Span<object>)' | ||
// F2(["a", "b"]); | ||
Diagnostic(ErrorCode.ERR_AmbigCall, "F2").WithArguments("Program.F2(System.Span<string>)", "Program.F2(System.Span<object>)").WithLocation(11, 9)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't feel right to me, but I can see that it adheres to the specification. I think we should resolve at the same time as #70238, hopefully in 17.9.
Collection expressions: prefer ReadOnlySpan<T> over Span<T> in overload resolution (#70328)
See updated better conversion from expression: dotnet/csharplang#7591
Fixes #70318