Bug 17930 – [Contract Programming] 23.3 In, Out and Inheritance

Status
NEW
Severity
minor
Priority
P3
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-10-23T04:46:21Z
Last change time
2024-12-15T15:24:19Z
Keywords
contracts
Assigned to
No Owner
Creator
Rob
Moved to GitHub: dlang.org#4071 →

Attachments

IDFilenameSummaryContent-TypeSize
1664contracts1.ddemonstrate the requirement for contracts in base in order to have them in derivedapplication/x-dsrc1190

Comments

Comment #0 by resmith5 — 2017-10-23T04:46:21Z
The section says "A function without an in contract means that any values of the function parameters are allowed. This implies that if any function in an inheritance hierarchy has no in contract, then in contracts on functions overriding it have no useful effect." But it appears that a compile error is generated when an overridden function has an "in" and the function it is overriding does not, rather than the contract having no effect - a compile error is encountered: contracts.d(34): Error: function contracts.TestContractsDerived.someFunction cannot have an in contract when overridden function contracts.TestContractsBase.someFunction does not have an in contract makefile:77: recipe for target 'contracts' failed
Comment #1 by resmith5 — 2017-10-23T06:14:27Z
*** Issue 17929 has been marked as a duplicate of this issue. ***
Comment #2 by resmith5 — 2017-10-23T06:22:37Z
In addition to class Base { myFunc() { } } class Derived : Base { myFunc(int a) in { assert(a >= 0); } body { } } getting a compile error. In the following situation: class Base2 { myFunc(int a) in { assert(a >= 0); } body { } } class Derived2 : Base2 { myFunc(int a) { } } calling Derived2.myFunc is subject to the constraint in Base2.myFunc. That behavior should probably be noted in the documentation.
Comment #3 by resmith5 — 2017-10-23T06:25:52Z
Forgot return types on functions. Also, the function in Derived2 should have "override".
Comment #4 by resmith5 — 2017-10-25T10:42:57Z
Created attachment 1664 demonstrate the requirement for contracts in base in order to have them in derived
Comment #5 by resmith5 — 2017-10-25T11:08:27Z
Sorry, please disregard comments 2 and 3, was mistaken about base class method contract applying to a derived method with no contract.
Comment #6 by robert.schadek — 2024-12-15T15:24:19Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dlang.org/issues/4071 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB