www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12247] New: in contract in interfaces is not checked

https://d.puremagic.com/issues/show_bug.cgi?id=12247

           Summary: in contract in interfaces is not checked
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: public mullakh.com



02:13:48 PST ---
dmd 2.064.2

----test.d ---

import std.stdio: writefln;

interface I
{
    int foo(int i)
        in { assert(i > 7); }
        out (result) { assert(result & 1); }

    void bar();
}

class Impl : I
{
    int foo(int i)
    {
        writefln("%s: %s", __FUNCTION__, i);

        return i;
    }

    void bar()
    {
        writefln("%s", __FUNCTION__);
    }
}

void main()
{
    I i = new Impl;

    i.foo(7); // in contract do not satisfied, though executed.
    i.bar(); 

    i.foo(8); // throws
}


---- output ---

$ dmd test.d  && ./test
test.Impl.foo: 7
test.Impl.bar
test.Impl.foo: 8
core.exception.AssertError test(8): Assertion failure
----------------
5   test                                0x0000000106a454ea _d_assertm + 38
6   test                                0x0000000106a3901f void
test.__assert(int) + 23
7   test                                0x0000000106a390da int
test.I.foo(int).void __ensure(ref const(int)) + 26
8   test                                0x0000000106a3916b int
test.Impl.foo(int) + 139
9   test                                0x0000000106a39000 _Dmain + 80
10  test                                0x0000000106a51805 void
rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).runAll().void __lambda1() + 33
11  test                                0x0000000106a51751 void
rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate()) + 45
12  test                                0x0000000106a517b1 void
rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()
+ 45
13  test                                0x0000000106a51751 void
rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate()) + 45
14  test                                0x0000000106a516cd _d_run_main + 449
15  test                                0x0000000106a39034 main + 20
16  libdyld.dylib                       0x00007fff8f6dd5fd start + 1
17  ???                                 0x0000000000000001 0x0 + 1

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