Consider: struct S{ int x=1; invariant(){assert(x==1);} void foo(){x=2;bar(1);} void bar(int i){x=i;} } void main(){ S s; s.foo(); } This should run fine, but currently it throws an AssertError. Because of this, D's invariant is mostly useless outside toy examples.
I've changed the title to better reflect what (I think) you're asking for. Please correct if I've missed the point. Note that the compiler is working exactly to spec here (for once), so this is an enhancement. An alternative approach is to make bar private/protected, or put the body of bar into a private/protected function that both foo and bar can call.
If it works for private functions that is fine. I could have sworn I tried it both with private and public bar, but private bar seems to work. I am closing this. sry for the noise.