Should alias this support implicit construction in function calls and return statements?
Simen Kjaeraas
simen.kjaras at gmail.com
Thu Dec 13 06:25:10 PST 2012
As discussed deep in the thread "Is there any reason why arithmetic
operation
on shorts and bytes return int?"[1], D currently does not support this
behavior:
struct bbyte {
byte b;
alias b this;
}
void foo(bbyte b) {}
void baz() {
byte b;
foo(b); // Cannot implicitly convert byte to bbyte.
}
bbyte baz( ) {
byte b;
return b; // Cannot implicitly convert byte to bbyte.
}
Kenji Hara points out, and I myself thought, that this was a deliberate
design choice. Walter's post[2] in the aforementioned thread indicates
(but does not make clear-cut) that he also thinks this implicit
construction is desirable.
A previous discussion with Andrei[3] about implicit conversion of nameless
tuples to named tuples resulted in a bug report[4], and it is clear that
his view also supports some such form of implicit conversion.
A long time ago, when dinosaurs roamed the earth, walterandrei.pdf[5]
suggested that opImplicitCastTo and opImplicitCastFrom take care of this
conversion. Is anything like this still on the drawing board? Should alias
this do it? How do we deal with cases were one field is alias this'd, and
other fields are not?
[1]:
http://forum.dlang.org/thread/mailman.2599.1355228650.5162.digitalmars-d@puremagic.com?page=3#post-mailman.2625.1355305365.5162.digitalmars-d:40puremagic.com
[2]:
http://forum.dlang.org/thread/mailman.2599.1355228650.5162.digitalmars-d@puremagic.com?page=3#post-kaatc0:24hgn:242:40digitalmars.com
[3]:
http://forum.dlang.org/thread/sedknwtlaefrxuflnbez@forum.dlang.org?page=8#postjul0qv:242l9d:241:40digitalmars.com
[4]: http://d.puremagic.com/issues/show_bug.cgi?id=8570
[5]: http://s3.amazonaws.com/dconf2007/WalterAndrei.pdf
--
Simen
More information about the Digitalmars-d
mailing list