[Issue 5906] Just pre-conditions at compile-time when arguments are static

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 7 18:33:48 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=5906



--- Comment #9 from yebblies <yebblies at gmail.com> 2013-03-08 13:33:42 EST ---
(In reply to comment #8)
> (In reply to comment #7)
> 
> > This can be done by converting precondition bodies to expressions then
> > const-folding them.  Non-trivial, but possible.
> 
> Thank you for the note, that seems better than having nothing.
> 
> 
> > This only makes sense if we define violating a function's precondition as
> > invalid code.
> 
> This seems OK. What are possible downsides of this?

struct S(int a)
{
    void fun(int b) in { assert(a != b); } body {}
}

void main()
{
    foreach(i; TypeTuple!(1, 2, 3, 4))
    {
        auto s = S!i();
        if (i != 4)
            s.fun(4);
    }
}

This code would error 'cannot call S.fun with b == 4' etc even though S.fun
never actually gets called with 4.

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


More information about the Digitalmars-d-bugs mailing list