Skip to content

Convert local to method does not respect unsafe keyword #32976

@dibarbet

Description

@dibarbet

Version Used:
16.0.0 Preview 3.0 28529.153.d16.0
Steps to Reproduce:
Enable unsafe compiler flag.
Run 'Convert to Method' on GetPtr local function.

class ClassA
{
    public unsafe void UnsafeFunction()
    {
        byte b = 1;
        unsafe byte* GetPtr(byte* bytePt)
        {
            return bytePt;
        }
        var aReference = GetPtr(&b);
    }
}

Expected Behavior:
New function should be marked as unsafe.

class ClassA
{
    public unsafe void UnsafeFunction()
    {
        byte b = 1;
        var aReference = GetPtr(&b);
    }

    private static unsafe byte* GetPtr(byte* bytePt)
    {
        return bytePt;
    }
}

Actual Behavior:
New method not marked as unsafe and shows compiler error.

class ClassA
{
    public unsafe void UnsafeFunction()
    {
        byte b = 1;
        var aReference = GetPtr(&b);
    }

    private static byte* GetPtr(byte* bytePt)
    {
        return bytePt;
    }
}

unsafe_converted_method

Metadata

Metadata

Assignees

Labels

Area-IDEBugIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions