Skip to content

binding: do not stop overload resolution at the first ambiguous pair - #46

Merged
rameel merged 1 commit into
mainfrom
binding/resolve-past-ambiguous-pair
Nov 19, 2026
Merged

rameel merged 1 commit into
mainfrom
binding/resolve-past-ambiguous-pair

Conversation

@rameel

@rameel rameel commented Nov 19, 2026

Copy link
Copy Markdown
Owner

MethodResolver compared each candidate with the best one so far and reported an ambiguous match as soon as two candidates were equally specific, even if a later candidate was more specific than both. For example, string.Concat(arr) with a string[] argument failed with Ambiguous match found: Concat(params object[]) and Concat(IEnumerable<string>) are equally specific for it, although Concat(params string[]) is better than both.

This PR remembers the ambiguity and continues, as System.DefaultBinder does. That walk compares a candidate only with the best one at the time, so the selected method is also checked against the candidates before it. As in C#, a call with no method better than all the others stays ambiguous: with NoBest(object, string), NoBest(string, object), and NoBest(IComparable, string), the call NoBest("a", "b") is rejected (CS0121), although the last overload is better than the first one.

MethodResolver compared each candidate with the best one so far and
returned null as soon as two candidates were equally specific, even if
a later candidate was more specific than both. For a string[]
argument, string.Concat(arr) was reported as an ambiguous match:
Concat(params object[]) and Concat(IEnumerable<string>) are equally
specific for it, although Concat(params string[]) is better than both.

Remember the ambiguity and continue, as System.DefaultBinder does.
Unlike DefaultBinder, also check that the selected method is more
specific than the candidates before it, which it may not have been
compared with. As in C#, a call with no method better than all the
others stays ambiguous.
@rameel
rameel merged commit ff929b6 into main Nov 19, 2026
1 check passed
@rameel
rameel deleted the binding/resolve-past-ambiguous-pair branch November 19, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant