{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/19742","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/19742/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/19742/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/19742/events","html_url":"https://github.com/dotnet/roslyn/issues/19742","id":230930982,"number":19742,"title":"Overload resolution for GetEnumerator fails with optional parameters","user":{"login":"jskeet","id":17011,"avatar_url":"https://avatars2.githubusercontent.com/u/17011?v=3","gravatar_id":"","url":"https://api.github.com/users/jskeet","html_url":"https://github.com/jskeet","followers_url":"https://api.github.com/users/jskeet/followers","following_url":"https://api.github.com/users/jskeet/following{/other_user}","gists_url":"https://api.github.com/users/jskeet/gists{/gist_id}","starred_url":"https://api.github.com/users/jskeet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jskeet/subscriptions","organizations_url":"https://api.github.com/users/jskeet/orgs","repos_url":"https://api.github.com/users/jskeet/repos","events_url":"https://api.github.com/users/jskeet/events{/privacy}","received_events_url":"https://api.github.com/users/jskeet/received_events","type":"User","site_admin":false},"labels":[{"id":166673288,"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Compilers","name":"Area-Compilers","color":"5319e7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-05-24T06:14:24Z","updated_at":"2017-05-25T18:03:58Z","closed_at":null,"body":"(Originally reported in ECMA standardization; copied here at the suggestion of @MadsTorgersen as it may somewhat fall out of async enumerable work.)\r\n\r\nWhen iterating over a type that has a custom `GetEnumerator` method, it is claimed that after looking up the method group, the next step (in the C# 5 spec section 8.8.4) is to:\r\n\r\n> - Perform overload resolution using the resulting method group and an empty argument list. If overload resolution results in no applicable methods, results in an ambiguity, or results in a single best method but that method is either static or not public, check for an enumerable interface as described below. It is recommended that a warning be issued if overload resolution produces anything except an unambiguous public instance method or no applicable methods.\r\n\r\nHowever, that appears not to quite be the case:\r\n\r\n``` csharp\r\nusing System;\r\nusing System.Collections.Generic;\r\n\r\nclass Test\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        foreach(var x in new Test()) // error CS1579: foreach statement cannot operate on variables of type 'Test' because 'Test' does not contain a public definition for 'GetEnumerator'\r\n        {\r\n            Console.WriteLine(x);\r\n        }\r\n    }\r\n\r\n    public IEnumerator<int> GetEnumerator(int count = 10)\r\n    {\r\n        for (int i = 0; i < count; i++)\r\n        {\r\n            yield return i;\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nHere overload resolution with an empty argument list should be fine - I can call `new Test().GetEnumerator()`. There isn't an empty parameter list, but that's not the same thing.\r\n\r\n(The same problem occurs for `params int[] values`, so we've actually had an issue since C# 1.0!)\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/304080057","html_url":"https://github.com/dotnet/roslyn/issues/19742#issuecomment-304080057","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/19742","id":304080057,"user":{"login":"jcouv","id":12466233,"avatar_url":"https://avatars1.githubusercontent.com/u/12466233?v=3","gravatar_id":"","url":"https://api.github.com/users/jcouv","html_url":"https://github.com/jcouv","followers_url":"https://api.github.com/users/jcouv/followers","following_url":"https://api.github.com/users/jcouv/following{/other_user}","gists_url":"https://api.github.com/users/jcouv/gists{/gist_id}","starred_url":"https://api.github.com/users/jcouv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcouv/subscriptions","organizations_url":"https://api.github.com/users/jcouv/orgs","repos_url":"https://api.github.com/users/jcouv/repos","events_url":"https://api.github.com/users/jcouv/events{/privacy}","received_events_url":"https://api.github.com/users/jcouv/received_events","type":"User","site_admin":false},"created_at":"2017-05-25T18:03:58Z","updated_at":"2017-05-25T18:03:58Z","body":"Ah, I'd misunderstood the bug report. The current behavior is this code fails to compile (I edited the description to include the compiler error), but you would expect it to succeed."}}
{"actor":{"display_login":"jcouv"}}