[Issue 12321] Contracts of implemented interface method aren't called

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Oct 8 10:53:48 UTC 2020


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

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

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

--- Comment #5 from FeepingCreature <default_357-line at yahoo.de> ---
Not a bug - or rather, the issue is a different bug.

As per Liskov, a class may only widen, not narrow, its in-contracts. As such,
there is no point to calling foo's in-condition, since the interface method
already promised that no in-contract would be necessary for the function call.

The actual bug is that this specific combination of in-contracts is never
valid, and as such the compiler should inform us that if we want to have an
incondition on the class, we need to at least define one on the interface as
well. (Otherwise the class method contract is provably pointless, as per
above.) Such a warning already appears for class inheritance, but is not yet
implemented for class-interface inheritance.

I've filed that as https://issues.dlang.org/show_bug.cgi?id=21298 .

Note that if you put an `in(true);` on foo(), the child foo() will still be
ignored, because D interprets incontracts as "if any hierarchy contract passes,
the child contract is assumed to pass." You can change this behavior with my
flag `-preview=inclusiveincontracts`, whereupon you will get a "Logic error"
exception indicating that A's foo() contract was tighter than IA's contract.

--


More information about the Digitalmars-d-bugs mailing list