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.

Using capturing precondition in async method in struct lead to invalid IL #168

@SergeyTeplyakov

Description

@SergeyTeplyakov

This bug is related to the #157, but not similar.

Consider following code:

struct Foo
{
    public int Limit { get; set; }

    public Foo(int limit) : this()
    {
        Limit = 42;
    }

    public async Task<int> FooAsync()
    {
        Contract.Requires(Limit == 42);

        await Task.Delay(42);

        return 42;
    }
}

Running this code will lead to InvalidProgramException when preconditions are enabled.

CC version: 1.8+. This is not a regression, this stuff never worked properly.

Please note, the if the Contract.Requires will use arguments everything would be fine. Only when precondition is using this the app will fail.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions