Thread overview
[Issue 6648] New: fix invariant
Sep 11, 2011
timon.gehr@gmx.ch
[Issue 6648] Only call invariant once for a tree of public functions
Sep 12, 2011
yebblies
Sep 12, 2011
timon.gehr@gmx.ch
September 11, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6648

           Summary: fix invariant
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: timon.gehr@gmx.ch


--- Comment #0 from timon.gehr@gmx.ch 2011-09-11 11:22:02 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 12, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6648


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com
            Summary|fix invariant               |Only call invariant once
                   |                            |for a tree of public
                   |                            |functions
           Severity|normal                      |enhancement


--- Comment #1 from yebblies <yebblies@gmail.com> 2011-09-12 11:52:29 EST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 12, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6648


timon.gehr@gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX


--- Comment #2 from timon.gehr@gmx.ch 2011-09-11 18:57:15 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------