Missing compiler warning for not awaiting Task produced by delegate? #76721
Closed as not planned
Description
Version Used: main
Steps to Reproduce:
using System;
using System.Threading.Tasks;
internal delegate Task MyDelegate();
public class TestClass
{
public void M()
{
MyDelegate c = async () =>
{
await Task.Delay(1);
throw new Exception();
};
// Expecting to see: CS4014
// warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
// But no warning is produced.
c();
}
}
If I switch to a local function instead of a delegate, the warning is correctly reported.
using System;
using System.Threading.Tasks;
internal delegate Task MyDelegate();
public class TestClass
{
public void M()
{
async Task c()
{
await Task.Delay(1);
throw new Exception();
}
c();
}
}