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.

CCRewriter removes Assert/Assume calls but not precondition checks from iterator blocks/async methods #41

@SergeyTeplyakov

Description

@SergeyTeplyakov

I assume (pun intended) that this bug is related to #34.

Consider following code:

static bool Check()
{
    Console.WriteLine("Check!");
    return true;
}

private static IEnumerable<string> FooAsync1(string str)
{
    Contract.Assert(Check() && str != null );
    yield return str;
}

Rewriting this code with level < 4 (i.e. not in a Full mode) should remove Assert method call from the iterator block.

But in reality, ccrewriter removes anly method call itself, but leaves precondition check in the final IL code.

Running this code with Preconditions only, will print "Check" message on the screen.

The same behavior would be for async methods as well.

UPDATE: minor correction.
To reproduce this issue complexity of the expression matters but not where it was called (iterator block/async method/regular method):

private static void Foo(string str)
{
    // Check method would be called
    Contract.Assert(Check() && str != null);
    Console.WriteLine("Boo");
}

private static void Foo2(string str)
{
    // Call to Check method would be erased
    Contract.Assert(Check());
    Console.WriteLine("Boo");
}

With Preconditions only in Foo method Checkmethod would be called but inFoo2` method - not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions