Skip to content

Missing compiler warning for not awaiting Task produced by delegate? #76721

Closed as not planned
@Youssef1313

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();
    }
}

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions