[Issue 6856] Preconditions are not inherited

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 2 17:38:15 PDT 2011


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



--- Comment #12 from Don <clugdbug at yahoo.com.au> 2011-11-02 17:37:44 PDT ---
(In reply to comment #10)
> (In reply to comment #9)
> > This explicit widening of preconditions of virtual functions seems to be a
> > really niche feature.
> 
> I think it does makes some sense to be like this. You can see it as adding an
> extra method to a derived class, or class implementing an interface. 

Yes. But in those cases you mention, the syntax for accessing the base
functionality is different to the derived functionality. But here we have
something different:

    Derived c;
    Base b = c;
    c.foo(7); // OK
    b.foo(7); // fail -- precondition is not widened

Same function body gets used in both calls, BUT different contracts need to get
called.

> The
> derived class adding a new method() still satisfies the interface, in the same
> sense an overriden method accepting wider preconditions still satisfies the
> original precondition, and the interface.

Yes, it does, but why is that desirable? When do you actually want that? Only
in niche cases, I think.

-- 
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