-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-CompilersBugLanguage-C#Resolution-FixedThe bug has been fixed and/or the requested behavior has been implementedThe bug has been fixed and/or the requested behavior has been implementedVerified
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-CompilersBugLanguage-C#Resolution-FixedThe bug has been fixed and/or the requested behavior has been implementedThe bug has been fixed and/or the requested behavior has been implementedVerified