Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TryCastWithoutUsingAsNotNull with anonymous type kungfu introduces a compilation error when renaming symbols #379

Closed
Vannevelj opened this issue Jan 25, 2016 · 0 comments

Comments

@Vannevelj
Copy link
Owner

There is one scenario in which TryCastWithoutUsingAsNotNull breaks:

TryCastWithoutUsingAsNotNull_AnonymousTypeRenaming

The scenario as layed out in AnonymousTypeRenaming is not yet supported by Renamer.RenameAsync. We could do it ourselves manually but that would probably be rather expensive. It is a niche scenario though so it's not too horrible to leave unsupported for now.

I'm making this issue to keep track of it but it's not something I consider a must-fix until Roslyn supports it themselves.

For reference, the full test:

        public void TryCastWithoutUsingAsNotNull_AnonymousTypeRenaming()
        {
            var original = @"
using System;
using System.Text;

namespace ConsoleApplication1
{
    class MyClass
    {
        void Method()
        {
            object o = 5;
            if (o is int)
            {
                var x = (int) o;
                var y = new { x };
                var z = y.x;
            }
        }
    }
}";

            var expected = @"
using System;
using System.Text;

namespace ConsoleApplication1
{
    class MyClass
    {
        void Method()
        {
            object o = 5;
            var oAsInt32 = o as int?;
            if (oAsInt32 != null)
            {
                var y = new { oAsInt32 };
                var z = y.oAsInt32;
            }
        }
    }
}";

            VerifyDiagnostic(original, string.Format(TryCastWithoutUsingAsNotNullAnalyzer.Rule.MessageFormat.ToString(), "o"));
            VerifyFix(original, expected);
        }

This currently fails on the line var z = y.oAsInt32; which, in reality, is var z = y.x;

Related PR: dotnet/roslyn#5786

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant