Thread overview
[Issue 12247] in contract in interfaces is not checked
Mar 12, 2019
Simon Naarmann
Mar 12, 2019
Simon Naarmann
Dec 17, 2022
Iain Buclaw
Feb 26, 2023
Dennis
Feb 26, 2023
Simon Naarmann
May 18, 2023
FeepingCreature
May 18, 2023
FeepingCreature
March 12, 2019
https://issues.dlang.org/show_bug.cgi?id=12247

Simon Naarmann <eiderdaus@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |contracts
                 CC|                            |eiderdaus@gmail.com

--- Comment #1 from Simon Naarmann <eiderdaus@gmail.com> ---
This issue still exists in DMD 2.084.1, tested on Linux 64-bit.

In the example code, the interface's in contract should throw, but does not. Only the out contract throws as desired.

--
March 12, 2019
https://issues.dlang.org/show_bug.cgi?id=12247

Simon Naarmann <eiderdaus@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|Mac OS X                    |All

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=12247

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P3

--
February 26, 2023
https://issues.dlang.org/show_bug.cgi?id=12247

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |dkorpel@live.nl
         Resolution|---                         |DUPLICATE

--- Comment #2 from Dennis <dkorpel@live.nl> ---
This is working as designed, though it is somewhat controversial.

> The fundamental nature of 'in' contracts is that they are "loosened" on derivation. If an instance of B is passed to parameter A, then if either the contract for A or the contract for B passes, then it passes. It is NOT necessary for the A contract to pass.

See issue 6856

*** This issue has been marked as a duplicate of issue 6856 ***

--
February 26, 2023
https://issues.dlang.org/show_bug.cgi?id=12247

--- Comment #3 from Simon Naarmann <eiderdaus@gmail.com> ---
Ah, I wouldn't have guessed that absence of contract means an always-passing contract. Thanks!

I agree to close it as a duplicate of 6856.

--
May 18, 2023
https://issues.dlang.org/show_bug.cgi?id=12247

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

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

--- Comment #4 from FeepingCreature <default_357-line@yahoo.de> ---
Note that in theory there's `-preview=inclusiveincontracts`, which changes the way inconditions work to require (at runtime) that child in-contracts are a subset of parent in-contracts. Though I haven't worked on it for a while now, because we've generally reduced the amount of objects being passed to functions (or non-autogenerated methods), so it hasn't come up in a while.

--
May 18, 2023
https://issues.dlang.org/show_bug.cgi?id=12247

--- Comment #5 from FeepingCreature <default_357-line@yahoo.de> ---
Hm, apologies, nevermind - that seems unrelated.

Right now, "no in-contract" is equivalent to "in (true)".

`I::foo(int i) in (i > 7)` creates an in-contract of "at least i > 7 must be
permitted for foo".
`Impl::foo(int i)` has no additional in-contract, so it allows in all values,
causing the behavior in this bug report.

preview=inclusiveincontracts does not affect this. The only thing it would affect is if you wrote `Impl::foo(int i) in (false)`, which today would succeed if called with, say, `8`, because 8 would pass the interface in-contract, and it only has to pass the in-contract of any of the override parents (because they are implicitly inclusive). But `in (true)`, which writing no in-contract implicitly is, works with either behavior.

Sorry for the spam, feel free to delete both comments.

--