Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Synchronous postcondition for async generic method #275

@SergeyTeplyakov

Description

@SergeyTeplyakov

ccrewrite generates special 'async closure', moves postcondition for task-based method there (both with async keyword and without it) and 'chains' a call to CheckPost from this class with resulting task.

This behavior is critical, because async postconditions should be checked only when the task completes, but the logic is wrong for async postconditions in generic methods:

class Foo
{
  public static async Task<T> FooAsync() where T: class
  {
    Contract.Ensures(Contract.Result<T>() != null);
    await Task.Delay(42);
    return default(T);
  }
}

In this case synchronous postcondition is emitted:

// after rewriting
class Foo
{
  public static async Task<T> FooAsync() where T: class
  {
    // some stuff generated by C# compiler
    var task = ...

   RewriterMethods.Ensure(task.Result != null, "Contract.Result<T>() != null");
    return default(T);
  }
}

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions