D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4685 - in contract of base class affected by the body of the overriding function
Summary: in contract of base class affected by the body of the overriding function
Status: RESOLVED DUPLICATE of issue 7335
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-08-19 17:39 UTC by Andrej Mitrovic
Modified: 2015-06-09 05:11 UTC (History)
2 users (show)

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-19 17:39:30 UTC
This code is normal:

import std.conv;

class BasicDate
{
    string format(string spec)
    in
    {
        writeln("in basicdate.format contract");
        writeln(spec);
        assert(spec == "1234");
    }
    body
    {
        return "";
    }
}

class Date : BasicDate
{
    override string format(string spec)
    in  
    {
        writeln("in date.format contract");
        writeln(spec);
        assert(spec == "1234");
    }
    body
    {
        //~ string x;
        return "";
    }
}

import std.stdio;

unittest
{
    auto mydate = new Date;
    mydate.format("1234");
}

void main()
{
}

Prints:
in basicdate.format contract
1234

Now I uncomment the "string x" line in the overriding function:

import std.conv;

class BasicDate
{
    string format(string spec)
    in
    {
        writeln("in basicdate.format contract");
        writeln(spec);
        assert(spec == "1234");
    }
    body
    {
        return "";
    }
}

class Date : BasicDate
{
    override string format(string spec)
    in  
    {
        writeln("in date.format contract");
        writeln(spec);
        assert(spec == "1234");
    }
    body
    {
        string x;
        return "";
    }
}

import std.stdio;

unittest
{
    auto mydate = new Date;
    mydate.format("1234");
}

void main()
{
}

Prints:
in basicdate.format contract
(null)
in date.format contract
1234
Comment 1 Stewart Gordon 2010-08-20 06:32:34 UTC
Under DMD 1.063, it fails as written as writeln isn't defined, but if changed to writefln I get

in basicdate.format contract
xin date.format contract
1234

Under 2.048, I get the same, but if I change it to use writefln then I get

in basicdate.format contract
in date.format contract
1234
Comment 2 Walter Bright 2012-01-25 13:40:21 UTC

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