implicit conversion to mutable via alias this

Nils Boßung via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 16 10:22:10 PDT 2014


Last week I filed issues 12883 [1] and 12884 [2], and made dmd pull request 
#3654 [3] to fix them. The changes would make it possible to use alias this 
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?
Or maybe you think that PR #3654 is totally awesome and should be pulled? ;)

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



More information about the Digitalmars-d mailing list