www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - implicit conversion to mutable via alias this

reply Nils =?UTF-8?B?Qm/Dn3VuZw==?= <nilsbossung googlemail.com> writes:
Last week I filed issues 12883 [1] and 12884 [2], and made dmd pull request 

for implicit conversion to mutable when the conversion is otherwise not 
possible.

Issue 12883 is about structs. dmd's current rules for conversion of structs 
are essentially:
1) If the unqualified source and target types match, and the members can be 
converted, do that.
2) Otherwise, if the unqualified types do not match, try alias this.
3) Otherwise, fail.

I'd like to change step 2 to
2) Otherwise, try alias this.

That is, in particular, if the unqualified types match but the members can't 
be converted, try alias this.

Kenji rejected the pull request saying that conversion to mutable should be 
handled by postblit. As far as I can see, that doesn't work right now. And I 
don't see how it's supposed to work. We can't allow conversion to mutable 
just because there's a postblit. And there is no way to mark/overload the 
postblit for a const-stripping conversion, is there?

Kenji, could you elaborate on how postblit is supposed to take care of this?
Or maybe someone else has some insight?


As for classes (issue 12884), dmd already accepts alias this to mutable 
here. But one way or the other it's buggy.

The motivation for all this came from issue 12885 [4]:
There is a hack in place in dmd to allow implicit conversion of 
const(Rebindable!(const Object)) to mutable. In my opinion it's too 
permissive and lets code be accepted that should be rejected. With to-
mutable-via-alias-this the conversion could be implemented in Rebindable 
itself and the hack could be reverted.

[1] https://issues.dlang.org/show_bug.cgi?id=12883
[2] https://issues.dlang.org/show_bug.cgi?id=12884
[3] https://github.com/D-Programming-Language/dmd/pull/3654
[4] https://issues.dlang.org/show_bug.cgi?id=12885
Jun 16 2014
next sibling parent reply Nils =?UTF-8?B?Qm/Dn3VuZw==?= <nilsbossung googlemail.com> writes:
Anyone?
Jun 17 2014
parent reply Nils =?UTF-8?B?Qm/Dn3VuZw==?= <nilsbossung googlemail.com> writes:
bump
Jun 19 2014
parent Nils =?UTF-8?B?Qm/Dn3VuZw==?= <nilsbossung googlemail.com> writes:
I'd still appreciate feedback on this.
Jun 21 2014
prev sibling parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
I can only guess Kenji's reasons, but I believe it's related to 
DIP49, which he created:

http://wiki.dlang.org/DIP49

The DIP describes how copying between differently qualified types 
should work. I guess his stance is that this should always go via 
the postblit, probably to avoid uncertainties about postblit or 
alias this has priority over the other. IMO this makes sense.

(And you're right, this is currently not implemented.)
Jun 21 2014
parent Nils =?UTF-8?B?Qm/Dn3VuZw==?= <nilsbossung googlemail.com> writes:
On Saturday 21 June 2014 21:55,  wrote:

 I can only guess Kenji's reasons, but I believe it's related to
 DIP49, which he created:
 
 http://wiki.dlang.org/DIP49
Thanks a bunch. That sheds quite some light on it.
Jun 21 2014