Bug 6648 – Only call invariant once for a tree of public functions

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-09-11T11:22:00Z
Last change time
2011-09-11T18:57:15Z
Assigned to
nobody
Creator
timon.gehr

Comments

Comment #0 by timon.gehr — 2011-09-11T11:22:02Z
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.
Comment #1 by yebblies — 2011-09-11T18:52:29Z
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.
Comment #2 by timon.gehr — 2011-09-11T18:57:15Z
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.