{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/25838","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/25838/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/25838/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/25838/events","html_url":"https://github.com/dotnet/roslyn/issues/25838","id":310062019,"number":25838,"title":"'Introduce local for x' changes code and introduces errors","user":{"login":"vsfeedback","id":32854332,"avatar_url":"https://avatars3.githubusercontent.com/u/32854332?v=4","gravatar_id":"","url":"https://api.github.com/users/vsfeedback","html_url":"https://github.com/vsfeedback","followers_url":"https://api.github.com/users/vsfeedback/followers","following_url":"https://api.github.com/users/vsfeedback/following{/other_user}","gists_url":"https://api.github.com/users/vsfeedback/gists{/gist_id}","starred_url":"https://api.github.com/users/vsfeedback/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vsfeedback/subscriptions","organizations_url":"https://api.github.com/users/vsfeedback/orgs","repos_url":"https://api.github.com/users/vsfeedback/repos","events_url":"https://api.github.com/users/vsfeedback/events{/privacy}","received_events_url":"https://api.github.com/users/vsfeedback/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-30T13:08:01Z","updated_at":"2018-03-30T14:57:59Z","closed_at":null,"author_association":"NONE","body":"When extracting code with &quot;Introduce local for 'x'&quot; refactoring:\n- extension method calls get rewritten to use static method calls;\n- unnecessary casts get introduced\n\n_This issue has been moved from https://developercommunity.visualstudio.com/content/problem/63032/introduce-local-for-x-changes-code-and-introduces.html\nVSTS ticketId: 444218_\n_These are the original issue comments:_\n\nSam Harwell [MSFT] on ‎6‎/‎2‎/‎2017, 00:30 PM (300 days ago): <p>Hi Rafael,</p><p>I'm currently trying to reproduce this. I tested a handful of samples in both 15.2 and 15.3 Preview 1 with things like nullable types and LINQ helper methods, but was so far unable to observe the behavior you described. It sounds like you may have hit a special case related to your specific code that wasn't accounted for by the refactoring yet. Would you be able to share a code sample that reproduces this to help me track it down?</p><p>Thanks,</p><p>Sam</p>\n\nSam Harwell [MSFT] on ‎7‎/‎3‎/‎2017, 02:38 PM (269 days ago): <p>Thank you for your feedback! For us to investigate this further, could you please provide some sample code which reproduces the issue?  We look forward to hearing from you!</p>\n\nKevin Pilch [MSFT] on ‎7‎/‎24‎/‎2017, 03:29 PM (248 days ago): <p>Thank you for your feedback! Unfortunately, right now we don't have enough information to investigate this issue and find a solution. If this is still an issue for you, please update to our latest version. If you are still able to repro it, please provide us with more info! Thank you for helping us build a better Visual Studio!</p>\n\nRafael de Lima Reis on ‎3‎/‎27‎/‎2018, 01:37 PM (2 days ago): Repro steps.Create an extension method like below:       public static Runtime.CompilerServices.ConfiguredTaskAwaitable IgnoreContext(this Task task)        \\{            return task.ConfigureAwait(false);        }Call the method from some Task-valued expresion, e.g:         var text = await FileEx.ReadAllText(outputFilePath).IgnoreContext();Select \"await FileEx.ReadAllText(outputFilePath)\" and activate \"Introduce local for\" refactoring.Voilá:                        var task = FileEx.ReadAllText(outputFilePath);                        var text = await System.Threading.Tasks.TaskExtensions.IgnoreContext(task);We can observe:        1. The extension method call was rewritten as a static method call.        2. A type variable argument was introduced where there wasn't any.Depending on the case, the result can be way worse (the more complicated the line where you extract the code, the worse). I've seen casts being introduced where none was needed. More fundamentally, all these transformations introduces syntactic changes -- altering the original text of the program.Thanks.\n_These are the original issue solutions:_\n(no solutions)"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/377542451","html_url":"https://github.com/dotnet/roslyn/issues/25838#issuecomment-377542451","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/25838","id":377542451,"user":{"login":"sharwell","id":1408396,"avatar_url":"https://avatars1.githubusercontent.com/u/1408396?v=4","gravatar_id":"","url":"https://api.github.com/users/sharwell","html_url":"https://github.com/sharwell","followers_url":"https://api.github.com/users/sharwell/followers","following_url":"https://api.github.com/users/sharwell/following{/other_user}","gists_url":"https://api.github.com/users/sharwell/gists{/gist_id}","starred_url":"https://api.github.com/users/sharwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharwell/subscriptions","organizations_url":"https://api.github.com/users/sharwell/orgs","repos_url":"https://api.github.com/users/sharwell/repos","events_url":"https://api.github.com/users/sharwell/events{/privacy}","received_events_url":"https://api.github.com/users/sharwell/received_events","type":"User","site_admin":false},"created_at":"2018-03-30T14:57:59Z","updated_at":"2018-03-30T14:57:59Z","author_association":"MEMBER","body":"Here is a reformatted copy of the repro steps from the last comment:\r\n\r\n> 1. Create an extension method like below:\r\n>\r\n>     ```csharp\r\n>     public static ConfiguredTaskAwaitable IgnoreContext(this Task task)\r\n>     {\r\n>       return task.ConfigureAwait(false);\r\n>     }\r\n>     ```\r\n>\r\n> 2. Call the method from some Task-valued expresion, e.g:\r\n>\r\n>     ```csharp\r\n>     var text = await FileEx.ReadAllText(outputFilePath).IgnoreContext();\r\n>     ```\r\n>\r\n> 3. Select `await FileEx.ReadAllText(outputFilePath)` and activate \"Introduce local for\" refactoring. Voilá:\r\n>\r\n>     ```csharp\r\n>     var task = FileEx.ReadAllText(outputFilePath);\r\n>     var text = await System.Threading.Tasks.TaskExtensions.IgnoreContext(task);\r\n>     ```\r\n>\r\n> We can observe:\r\n>\r\n> 1. The extension method call was rewritten as a static method call.\r\n> 2. A type variable argument was introduced where there wasn't any.\r\n>\r\n> Depending on the case, the result can be way worse (the more complicated the line where you extract the code, the worse). I've seen casts being introduced where none was needed. More fundamentally, all these transformations introduces syntactic changes -- altering the original text of the program.\r\n>\r\n> Thanks."}}
{"actor":{"display_login":"sharwell"}}