[Issue 4685] New: in contract of base class affected by the body of the overriding function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Aug 19 17:39:33 PDT 2010
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 at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at 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: -------
More information about the Digitalmars-d-bugs
mailing list