0

I am writing a simple 2d physics engine and I've overridden == for my Vector2 struct as follows:

[Pure]
public static bool operator ==(Vector2 v1, Vector2 v2)
{
  Contract.Ensures(Contract.Result<bool>() == (v1.x == v2.x && v1.y == v2.y));

  return v1.x == v2.x && v1.y == v2.y;
}

However, when I go to use this in a Contract.Ensures for my Circle struct, I get the following:

public Vector2 Position
{
  get
  {
    Contract.Ensures(Contract.Result<Vector2>() == position);

    Contract.Assert(position == position); // Assert unproven: position == position

    return position;
  }
}

I added the assert as a way of debugging. position is just a private Vector2 field, and it is set by the sole Circle constructor in the struct. Vector2 is itself a struct.

durron597
  • 31,968
  • 17
  • 99
  • 158
Tom K.
  • 3
  • 4

1 Answers1

0

I think I found the answer to my problem. I'm using private fields to describe my contracts. Once I switched these references to use the public properties and then annotated my fields with [ContractPublicProperty("PropertyName")] the problems went away. I believe this is because the Circle struct didn't have visibility for the contracts in the Vector2 struct.

Tom K.
  • 3
  • 4