www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9412] New: Invariants allowed to call public functions indirectly

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9412

           Summary: Invariants allowed to call public functions indirectly
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid, spec
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: kekeniro2 yahoo.co.jp
            Blocks: 520


--- Comment #0 from kekeniro2 yahoo.co.jp 2013-01-27 21:34:53 PST ---
Invariants are not allowed to call public functions _directly_.(Issue 520)
However, they can do indirectly, and that makes an infinite loop.

Code:
//import std.stdio; // for trace log
class Inv {
    invariant() {
        //writeln("invariant");
        prv();
        //pub(); // not allowed
    }
    private void prv() const {
        //writeln("private");
        pub();
    }
    void pub() const {
        //writeln("public");
    }
}
void main() {
    auto test = new Inv();
    test.pub();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 27 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9412


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru


--- Comment #1 from Maxim Fomin <maxim maxim-fomin.ru> 2013-01-27 22:22:16 PST
---
From http://dlang.org/dbc.html:

"The code in the invariant may not call any public non-static members of the
class or struct, either directly or indirectly. Doing so will result in a stack
overflow, as the invariant will wind up being called in an infinitely recursive
manner. "

I understand that it does not mean that implementation enforces the rules.
Ability to call functions from invariants is a loophole, and there is
possibility to enter infinite loop in cases which are more complicated then
above. Human still can write code which avoids compiler constraints - the
question here is whether to introduce control flow for calling functions from
invariants, or throw exceptions, or just do nothing.

Either this should be marked as enhancement request, or RESOLVED-WONTFIX

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 27 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9412


kekeniro2 yahoo.co.jp changed:

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


--- Comment #2 from kekeniro2 yahoo.co.jp 2013-10-12 01:05:04 PDT ---
*** This issue has been marked as a duplicate of issue 10889 ***

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