Bug 4685 – in contract of base class affected by the body of the overriding function
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-08-19T17:39:00Z
Last change time
2015-06-09T05:11:39Z
Keywords
wrong-code
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2010-08-19T17:39:30Z
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 by smjg — 2010-08-20T06:32:34Z
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 by bugzilla — 2012-01-25T13:40:21Z
*** This issue has been marked as a duplicate of issue 7335 ***