Skip to content

"Name can be simplified" code fix results in invalid code (build error) #57767

@Sergio0694

Description

@Sergio0694

Version Used: Visual Studio 17.1 Preview 1

Steps to Reproduce:

  1. Paste the following code (pls don't judge me 🙈)
using System.Runtime.CompilerServices;

public ref struct A
{
    private void Foo()
    {
    }

    public readonly unsafe ref struct B
    {
        private readonly void* a;

        public void Dispose()
        {
            ((delegate*<ref byte, ref A>)(delegate*<ref byte, ref byte>)&Unsafe.As<byte, byte>)(ref *(byte*)a).Foo();
        }
    }
}

Expected Behavior:

Nothing should happen, this code is fine. Trust me.

Actual Behavior:

IntelliSense suggests to "simplify the name" on that Dispose line, which just nukes everything except Foo(). This obviously results in a compile error, given that B does not have a method named Foo() (and also removing that previous code is semantically different). Interestingly enough, the preview window for the refactor already shows the red quiggly line over the resulting Foo() call, so it would seem Roslyn does at least in part know already that the refactoring is actually invalid.

cc. @333fred @jaredpar just because Fred will probably block me on Discord after this, and Jared will probably have a laugh 😄

Additional notes:

Here's a smaller repro (note though that this code instead wouldn't actually be useful, but it's just to show the issue):

public struct A
{
    private void Foo()
    {
    }

    public readonly unsafe struct B
    {
        private readonly void* a;

        public void Dispose()
        {
            ((delegate*<ref byte, ref A>)&Unsafe.As<byte, A>)(ref *(byte*)a).Foo();
        }
    }
}

Metadata

Metadata

Labels

Area-IDEBughelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions