Issue with contracts and assertions

Rene Zwanenburg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 23 07:34:15 PDT 2014


On Friday, 23 May 2014 at 13:45:07 UTC, Andre wrote:
> Hi,
>
> for the attached code I noticed some strange behaviors.
> I compile the programm with: dmd main -unittest
> The expected assertion of the method c pre condition is
> not raised.
> It is only raised if class A not implements interface I.
>
> On the otherside the commented assertion in the invariant is 
> working
> fine.
>
> Is this a bug?
>
> Kind regards
> André
>
>
> interface I {
> 	void c();
> }
>
> class A : I {
> 	invariant() {
> 		//assert(false, "Assert INVARIANT"); // Working
> 	}
>
> 	void c()
> 	in {
> 		assert(false, "Assert IN");
> 	}
> 	body {
>
> 	}
> }
>
> unittest {
> 	A a = new A();
> 	a.c();
> }
>
> void main(){}

I'm not sure. An implementation shouldn't be allowed to have 
stricter pre-conditions than it's base class or interface. On the 
other hand it should be able to relax them.


More information about the Digitalmars-d-learn mailing list