Skip to content

Very bad bug: Sempaphore.WaitAsync gets filtered out of code generation #119

Description

@persn

Consider the following code

        private SemaphoreSlim semaphore = new(1);

        [Zomp.SyncMethodGenerator.CreateSyncVersion()]
        public async Task FooAsync(CancellationToken cancellationToken = default)
        {
            await semaphore.WaitAsync(cancellationToken);

            try
            {
                await Task.Delay(100, cancellationToken);
            }
            finally
            {
                semaphore.Release();
            }
        }

I was expecting it to become

        public void Foo()
        {
            semaphore.Wait(cancellationToken);

            try
            {
                global::System.Threading.Thread.Sleep(100);
            }
            finally
            {
                semaphore.Release();
            }
        }

However what I actually got was

        public void Foo()
        {
            try
            {
                global::System.Threading.Thread.Sleep(100);
            }
            finally
            {
                semaphore.Release();
            }
        }

Notice that the semaphore.Wait(cancellationToken); is missing from the code generation, and the semaphore will become out of sync

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions