Roslyn: Applying suggested changes "IDE0018 Variable declaration can be inlined" generates non-compilable code

Created on 15 Oct 2018  路  1Comment  路  Source: dotnet/roslyn

REPRODUCTION STEPS

  • latest Visual Studio 2017 version
  • create new Visual Studio Project of type "Console App (.NET Framework)" (.NET Framework 4.7)
  • paste the following code into the generated Main method body (Program.cs attached)

        var actionArray = new[] 
        {
            new Action(() =>
            {
                var someValue = "2";
                int valueAsInt; // suggested changes in this line
                if (int.TryParse(someValue, out valueAsInt))
                {
                    Console.WriteLine(valueAsInt);
                }
            })
        };
    
  • apply suggested changes "IDE0018 Variable declaration can be inlined" in the line "int valueAsInt;"

  • the line below is changed to "if (int.TryParse(someValue, out intvalueAsInt))" which will produce a build error
  • the line should be "if (int.TryParse(someValue, out int valueAsInt))"

_This issue has been moved from https://developercommunity.visualstudio.com/content/problem/341937/applying-suggested-changes-ide0018-variable-declar.html
VSTS ticketId: 690311_
_These are the original issue comments:_
(no comments)
_These are the original issue solutions:_

Jinu Joseph [MSFT] solved on 10/14/2018, 05:04 PM (8 hours ago), 0 votes:

Thank you for your feedback! This issue appears to be identical to https://github.com/dotnet/roslyn/issues/17743 We recommend that you vote on and follow the earlier reported issue for updates and fix notifications.

Area-IDE Bug Developer Community Resolution-Fixed

Most helpful comment

I can take this one

>All comments

I can take this one

Was this page helpful?
0 / 5 - 0 ratings