Description
- Proposal added
- Discussed in LDM
- Decision in LDM
- Finalized (done, rejected, inactive)
- Spec'ed
Based on a suggestion by the LDM, we propose to add the following overload resolution tiebreaker in some future version of C#.
Two applicable methods can have identical parameter types, but differ in argument ref kind. This can occur when the ref kind of one is by value, but the other is in
. For example, for the methods
void M(in int x) {}
void M(int y) {}
These would be ambiguous at the call site
M(expr);
Proposal (was implemented in 15.6):
We propose a new tie-breaker: if there is an ambiguity and there is no in at the call-site, then the byval overload wins.
This tie-breaker comes after existing tie-breakers.
Alternative proposal:
We propose a new tie-breaker as follows:
- If the expression is an lvalue, we bind to the overload with an
in
parameter. - Otherwise, we bind to the overload with a value parameter.
Because it is not clear how valuable this tie-breaker would be, we are deferring it to some future time when we can judge the impact of ambiguities of this sort.
In the meantime, users can explicitly select the desired overload by using a named argument, an explicit in
at the callsite, or by changing the declarations of the methods to be sufficiently different.