0

I'm hoping someone can help me..

I have a C# class in which I have implemented a Code Contracts invariant. My methods keep throwing "invariant unproven" errors unless I explicitly assert the invariant is true.

My suspicion is that the problem derives from the use of void return type?

[ContractInvariantMethod]
private void FooInvariant()
{
    Contract.Invariant(!(Foo1.GetState() == "failed") || (Foo2.Get_State() == "off"));
}

//this method works fine
public void FooBar()
{
    Foo1.IncreaseInternalInt();
    Contract.Assert(!(Foo1.GetState() == "failed") || (Foo2.Get_State() == "off"));
}

//As does this method
public void FooBarTwo()
{
    Contract.Assert(!(Foo1.GetState() == "failed") || (Foo2.Get_State() == "off"));
    Foo1.IncreaseInternalInt();
}

//This method doesn't work
public void FooBarThree()
{
    Contract.Requires(!(Foo1.GetState() == "failed") || (Foo2.Get_State() == "off"));
    Foo1.IncreaseInternalInt();
}

//This method doesn't work either
public void FooBarFour()
{
    Contract.Ensures(!(Foo1.GetState() == "failed") || (Foo2.Get_State() == "off"));
    Foo1.IncreaseInternalInt();
}

I hope I haven't dumbed this down too much.

Any help would be greatly appreciated!

krex
  • 345
  • 3
  • 8
  • 21
  • I never though to mention/ask if the problem is related to my predicate logic: A => B .. (!A) || (B) – krex Dec 12 '13 at 02:19
  • This program doesn't look complete - what are Foo1 and Foo2? – Stephen J. Anderson Dec 12 '13 at 08:31
  • It's not complete, I tried to supply the context of my problem without the 6 or 7 other classes that are involved. I'm developing a program in Atelier-B using B-Method and transferring that to Code Contracts, so the invariants get pretty beefy. – krex Dec 13 '13 at 00:54
  • Can you replicate the problem with a toy project containing just three classes (Foo, Foo1 and Foo2)? It's going to be very hard to diagnose the problem without a [short but complete program](http://www.yoda.arachsys.com/csharp/complete.html). – Stephen J. Anderson Dec 13 '13 at 13:44

0 Answers0