[Issue 21689] Contracts (in/out) is not checked when for interfaces methods

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 9 11:13:08 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21689

anonymous4 <dfj1esp02 at sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec
             Status|NEW                         |RESOLVED
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=21298
         Resolution|---                         |INVALID

--- Comment #1 from anonymous4 <dfj1esp02 at sneakemail.com> ---
Umm, contract programming is a system with goals and rules to achieve those
goals. If you want to make assertions without much metaphysics, you can do it
with assert expression:

interface I {
    int func(int x);
}

class CI : I {
    int func(int x)
    {
        assert(x > 0);
        return x*x;
    }
}

I agree with issue 21298, restriction of the contract in the subtype is a
programming mistake and should be rejected by the compiler.

--


More information about the Digitalmars-d-bugs mailing list