preconditions and interfaces
Antonio Corbi
antonio at ggmail.com
Sun Jan 20 15:39:49 UTC 2019
Hi all,
Playing with interfaces and preconditions in methods I get
strange results with dmd-2.0.84.0 but also with dmd-nightly. My
code is like this:
-------------
import std.stdio;
interface Thing2D {
void width(int w)
in {
writeln("Thing2D.width contract w = ",w);
assert(w > 0);
}
}
class Line : Thing2D {
override void width(int w)
in {
writeln("Line.width contract w = ",w);
assert(w >= 0);
}
do {
writeln("Line.width: w = ", w);
}
}
void main() {
auto l = new Line;
l.width(-1);
}
---------------
1) With dmd-2.084.0 I get:
./ifaceprecond
Thing2D.width contract w = 2
Line.width: w = -1
2) With dmd-nightly (as of today) I get random values for
interface's 'w':
./ifaceprecond
Thing2D.width contract w = 647271536
Line.width: w = -1
I think this should be an error caught by the contract, isn't it?
Thx!
Antonio
More information about the Digitalmars-d-learn
mailing list