www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4685] New: in contract of base class affected by the body of the overriding function

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4685

           Summary: in contract of base class affected by the body of the
                    overriding function
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2010-08-19
17:39:30 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 19 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4685


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |smjg iname.com
            Version|D2                          |D1 & D2


--- Comment #1 from Stewart Gordon <smjg iname.com> 2010-08-20 06:32:34 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 20 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4685


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |DUPLICATE


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2012-01-25
13:40:21 PST ---
*** This issue has been marked as a duplicate of issue 7335 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 25 2012