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

Extract Method refactoring fails to capture inputs/outputs when unsafe blocks are included #4950

Closed
Pilchie opened this issue Sep 2, 2015 · 3 comments · Fixed by #45334
Closed

Comments

@Pilchie
Copy link
Member

Pilchie commented Sep 2, 2015

From @AArnott:

using System;

class Program {
    static void Main(string[] args) {
        object value = args;

        // extract from here
        IntPtr p;
        unsafe
        {
            object t = value;
            p = IntPtr.Zero;
        }
        // to here

        Console.WriteLine(p);
    }
}

Open the C# console app in Dev14 and the Program.cs file.
Select lines 7 - 12 and execute the Extract Method command.

Expected
A new method that takes an object as a parameter and returns an IntPtr is created, and an invocation of that method replaces the selected lines that passes in "value" as the parameter and assigns the result to "IntPtr p".

Actual
A method is created that takes no parameters and returns void. Two compile errors are created by the refactoring as a result.

@Pilchie Pilchie added this to the 1.2 milestone Sep 2, 2015
@Pilchie Pilchie modified the milestones: 1.2, 1.3 Jan 23, 2016
@Pilchie Pilchie modified the milestones: 2.0 (RC), 1.3, Unknown May 27, 2016
@Pilchie Pilchie added the help wanted The issue is "up for grabs" - add a comment if you are interested in working on it label May 27, 2016
@AArnott
Copy link
Contributor

AArnott commented Feb 10, 2019

This repros with unchecked blocks as well.

@gafter
Copy link
Member

gafter commented Feb 10, 2019

I suspect this may be a bug in the region analysis APIs. If you discover that is the case, please assign to me and Area-Compilers.

@CyrusNajmabadi
Copy link
Member

Yes. this is a bug in the region analysis APIs. Assigning to @gafter

@gafter the core issue is here: We call AnalyzeDataFlow on the pair of statements IntPtr p; and unsafe { }. This fails immediately with a non-successful result. Debugging in a tiny bit, this is because the compiler doesn't get a boundnode for the unsafe { } block. Because there's no end bound node, nothing works.

@gafter gafter added 3 - Working and removed help wanted The issue is "up for grabs" - add a comment if you are interested in working on it labels Jun 19, 2020
gafter pushed a commit to gafter/roslyn that referenced this issue Jun 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants