Skip to content

Extension blocks: extension method called from constructor is marked as unused #80645

@jhinder

Description

@jhinder

Version Used: VS 18.0.0 Insiders [11109.219]

Steps to Reproduce:
Observe the method declaration for M.

static class D
{
    class C
    {
        public C()
        {
            this.M();
        }
    }

    extension (C c)
    {
        private void M()
        {
        }
    }
}

Expected Behavior:
Since the method is used, it is not marked as unused.

Actual Behavior:
The method M is greyed out and IDE0051 is reported. If you select the code fix "Remove unused member", the code breaks.

Note: if you declare the extension method in the "old way" (i.e. private static void M(this C c)), this will not occur.

In the following screenshot, you can even see that the syntax highlighter shows that the method is actually used.
Image

Metadata

Metadata

Assignees

Labels

4 - In ReviewA fix for the issue is submitted for review.Area-IDEFeature - Extension EverythingThe extension everything featurehelp 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

Status
Active/Investigating

Relationships

None yet

Development

No branches or pull requests

Issue actions