Skip to content

CC0023 incorrectly raised to Func<T> with Elvis Operator #214

@giggio

Description

@giggio

This will incorrectly raise CS0023 on the 3rd line:

void Foo<T>(Func<T> func)
{
    func?.Invoke();
}

Message is: Operator '?' cannot be applied to operand of type 'T'

If you add a class restriction to the method Foo it will not raise CS0023:

void Foo<T>(Func<T> func) where T : class
{
    func?.Invoke();
}

The target of the operator if Func<T>, not T, so I believe this is a bug.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions