D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4562 - D2 Language Docs: http://www.digitalmars.com/d/2.0/dbc.html
Summary: D2 Language Docs: http://www.digitalmars.com/d/2.0/dbc.html
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dlang.org (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-01 14:58 UTC by Andrej Mitrovic
Modified: 2012-01-04 07:45 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2010-08-01 14:58:13 UTC
It states:

"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 my example proves otherwise:

class A
{
    int test(int x)
    {
        return x * 2;
    }
}
    
class B : A
{
    int test(int x)
    in
    {
        assert(x == 20);
    }
    body
    {
        return x * 2;
    }
}

void main() {
    B b = new B;
    b.test(10);
}

This will raise an assert error, which would negate the statement "in contracts on functions overriding it have no useful effect.".
Comment 1 Andrej Mitrovic 2012-01-04 07:45:24 UTC
This has turned into a CT error in 2.057 and probably earlier:

test.d(11): Error: function test.B.test cannot have an in contract when overriden function test.A.test does not have an in contract

I think it's ok to close it then.