Skip to content
This repository has been 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

Open
SergeyTeplyakov opened this issue May 8, 2015 · 0 comments

Comments

@SergeyTeplyakov
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant