error in return statement
Steven Schveighoffer
schveiguy at yahoo.com
Tue Feb 10 09:02:03 PST 2009
"zorran" wrote
> possibly error in return statement:
> ====
> bool fn1(Object o1, Object o2 ) {
> return o1.opEquals(o2); // opEquals return int
> }
> ====
>
> compiler writes:
> "Error: cannot implicitly convert expression (o1.opEquals(o2)) of type int
> to bool"
>
> But:
> ====
> bool fn2() {
> return 1;
> }
> ====
> compile ok!
>
> DMD 1.039
It's because you are using a literal. A literal '1' is sort of magic as it
can be interpreted as many different types, including int, float, bool, etc.
BTW, in DMD 2, Object.opEquals() returns bool (long-standing bug). Don't
think it's planned for D1 however.
-Steve
More information about the Digitalmars-d-bugs
mailing list