Skip to content

Name of expression with type name argument should not generate OperationKind.None in Operation tree #41963

@mavasani

Description

@mavasani

Consider the below unit test:

        [CompilerTrait(CompilerFeature.IOperation)]
        [Fact]
        public void NameOfExpressionWithTypeName()
        {
            string source = @"
class Class1
{
    public string M()
    {
        return /*<bind>*/nameof(Class1)/*</bind>*/;
    }
}
";
            string expectedOperationTree = @"
INameOfOperation (OperationKind.NameOf, Type: System.String, Constant: """"Class1"""") (Syntax: 'nameof(Class1)')
      IOperation:  (OperationKind.None, Type: null) (Syntax: 'Class1')";
            var expectedDiagnostics = DiagnosticDescription.None;

            VerifyOperationTreeAndDiagnosticsForTest<InvocationExpressionSyntax>(source, expectedOperationTree, expectedDiagnostics);
        }

The above unit test demonstrates that the tree has a none operation, which is normally reserved for not yet implemented operations for new language features.

This leads to bunch of our analyzers to bail out on all code with such name of expressions, for example all flow based analyzers, analyzers that flag symbols without read/write references (such as unused parameter/local/private field, etc.), which conservatively bail out on all method bodies with any OperationKind.None within the operation tree. Ideally, we should not have OperationKind.None for such a common code construct.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions