dotnet/roslyn

Bug in Move Type to Namespace refactoring - usings not added for namespaces in same file

Aperta

#50.672 aperta il 21 gen 2021

 (11 commenti) (0 reazioni) (1 assegnatario)C# (4257 fork)batch import
Area-IDEBughelp wanted

Metriche repository

Star
 (20.414 stelle)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

Version Used: Visual Studio 16.9.0 Preview 3.0

Sample Code:

using System;

namespace Tests
{
    internal class Foo
    {
        public static int Do(Inner.Data d) => 42;
    }
}

namespace Tests {
    namespace Inner
    {
        public class App
        {
            static void Main()
            {
                Console.WriteLine(Foo.Do(new Data()));
            }
        }
        public class Data { }
    }
}

Steps to Reproduce:

  1. Move type Foo to Namespace Something.Else

Expected Behavior: Working Code

Actual Behavior: Compile Error

Code after refatoring:

using Something.Else;
using System;

namespace Something.Else
{
    internal class Foo
    {
        public static int Do(Inner.Data d) => 42;
    }
}

namespace Tests
{
    namespace Inner
    {
        public class App
        {
            static void Main()
            {
                Console.WriteLine(Foo.Do(new Data()));
            }
        }
        public class Data { }
    }
}

Expected Code:

using Something.Else;
using System;
using Tests.Inner;

namespace Something.Else
{
    internal class Foo
    {
        public static int Do(Data d) => 42;
    }
}

namespace Tests
{
    namespace Inner
    {
        public class App
        {
            static void Main()
            {
                Console.WriteLine(Foo.Do(new Data()));
            }
        }
        public class Data { }
    }
}

Guida contributor