[Issue 20428] Precondition bug for in/out

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 4 09:20:48 UTC 2019


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

FeepingCreature <default_357-line at yahoo.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |default_357-line at yahoo.de

--- Comment #1 from FeepingCreature <default_357-line at yahoo.de> ---
Sorta a bug but not really. More a really confusing aspect of how in-conditions
work.

By substitutability, a subclass can always say that it chooses to accept more
data as parameters than its parent class or interface demands. Contracts are an
extension of this mechanism, so an in-condition on an interface is mostly
useless - the subclass only *has to* accept all the values that the interface
in-condition lets through; but it can always choose to accept more values.
(This is fundamental to what inheritance formally means.)

In D, a lack of in-condition is taken to mean "the function takes any value
allowed by the type." As such, you can always override a method with an
in-condition with one that doesn't have an in-condition, which is taken to
dissolve the in-condition.

Now, from a language design perspective it would probably be better if "no
in-condition" meant "copy the in-condition of the parent interface" and you'd
signal the desire to accept any value with something like "in (true)". However,
that'd be a feature proposal, not a bug.

--


More information about the Digitalmars-d-bugs mailing list