{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/5605","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/5605/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/5605/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/5605/events","html_url":"https://github.com/dotnet/roslyn/issues/5605","id":109256894,"number":5605,"title":"[Proposal] Overload resolution hint for overloads that have exactly the same priority","user":{"login":"ashmind","id":166396,"avatar_url":"https://avatars.githubusercontent.com/u/166396?v=3","gravatar_id":"","url":"https://api.github.com/users/ashmind","html_url":"https://github.com/ashmind","followers_url":"https://api.github.com/users/ashmind/followers","following_url":"https://api.github.com/users/ashmind/following{/other_user}","gists_url":"https://api.github.com/users/ashmind/gists{/gist_id}","starred_url":"https://api.github.com/users/ashmind/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashmind/subscriptions","organizations_url":"https://api.github.com/users/ashmind/orgs","repos_url":"https://api.github.com/users/ashmind/repos","events_url":"https://api.github.com/users/ashmind/events{/privacy}","received_events_url":"https://api.github.com/users/ashmind/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Language%20Design","name":"Area-Language Design","color":"5319e7"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Enhancement","name":"Enhancement","color":"fc2929"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Feature%20Request","name":"Feature Request","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-10-01T08:58:09Z","updated_at":"2015-10-06T04:58:22Z","closed_at":null,"body":"#### Problem\r\n\r\nThere are cases when there is need for two overloads that perform a same function over different types.\r\nExample:\r\n```csharp\r\nTValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key);\r\nTValue GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key);\r\n```\r\n\r\nThis pattern breaks when something belongs to both types, e.g. `d.GetValueOrDefault` would break if `d` is a `Dictionary<,>`, since it implements both interfaces. There is no good workaround other than forcing user to cast, or implementing additional overloads for common types.\r\n\r\nAnother case (more of an edge case) I had recently was\r\n```csharp\r\nbool operator==(MyType x, OtherType1 y);\r\nbool operator==(MyType x, OtherType2 y);\r\n```\r\nwhich breaks on a common case of `x == null` as `null` can belong to either type.\r\n\r\n#### Proposal\r\n\r\nI feel that in most of those cases it does not matter which overload will be selected for types that match both -- as long as it is actually selected and user does not have to cast.\r\n\r\nSo the suggestion is to provide a hint to the compiler -- specifying which overload to pick when all of them have exactly the same priority.\r\n\r\nTo avoid polluting the language, I suggest an attribute, e.g.:\r\n```csharp\r\nTValue GetValueOrDefault<TKey, TValue>([PrimaryOverload] this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key);\r\n```\r\n\r\n```csharp\r\nbool operator==(MyType x, [PrimaryOverload] OtherType1 y);\r\n```\r\n\r\nNot sure what would be the best name -- open to feedback."},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/145742273","html_url":"https://github.com/dotnet/roslyn/issues/5605#issuecomment-145742273","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/5605","id":145742273,"user":{"login":"ashmind","id":166396,"avatar_url":"https://avatars.githubusercontent.com/u/166396?v=3","gravatar_id":"","url":"https://api.github.com/users/ashmind","html_url":"https://github.com/ashmind","followers_url":"https://api.github.com/users/ashmind/followers","following_url":"https://api.github.com/users/ashmind/following{/other_user}","gists_url":"https://api.github.com/users/ashmind/gists{/gist_id}","starred_url":"https://api.github.com/users/ashmind/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashmind/subscriptions","organizations_url":"https://api.github.com/users/ashmind/orgs","repos_url":"https://api.github.com/users/ashmind/repos","events_url":"https://api.github.com/users/ashmind/events{/privacy}","received_events_url":"https://api.github.com/users/ashmind/received_events","type":"User","site_admin":false},"created_at":"2015-10-06T04:58:22Z","updated_at":"2015-10-06T04:58:22Z","body":"@gafter OK I see the confusion, I just understood your \"section\" term as referring to the whole of 7.5.3.2 and so was confused as it's not just about identical overloads. Now I see it, thanks.\r\n\r\nAnyway, does my new spec make sense?"}}