DIP30, delegates more destruction for your pleasure
deadalnix
deadalnix at gmail.com
Thu Mar 14 04:58:53 PDT 2013
On Thursday, 14 March 2013 at 11:42:29 UTC, Timon Gehr wrote:
> On 03/14/2013 04:12 AM, deadalnix wrote:
>> ...
>>>
>>
>> It is a tempting idea, but do not work. Consider :
>>
>> void delegate() immutable a;
>> const void delegate() b = a;
>>
>> This would be forbidden as covariance of function parameters
>> and
>> transitivity act in opposite directions.
>
> Uh, why?
>
This would be forbidden, according to the rule expressed in the
post + transitivity guaranty. That is not the position I defend.
> In my current opinion, it should be as follows:
>
> void main(){
> void delegate()inout w;
> void delegate()immutable i;
> void delegate()const c;
> void delegate() m;
> void delegate()const inout wc;
>
> // The following cases should be disallowed:
>
> i=c; // there may be mutable references to context
> c=m; // m may modify context
> i=m; // m may modify context
> w=i; // cannot use immutable as const or mutable
> w=m; // cannot use mutable as immutable
> w=c; // cannot use const as immutable
> wc=m;// cannot use mutable as immutable
> wc=c;// wc will access context as const or immutable
> i=w; // inout could mean const or mutable
> c=w; // inout could mean mutable
> i=wc; // inout const could mean const
>
> // These should be allowed:
>
> c=i; // certainly const if only immutable data accessed
> c=wc;// certainly const if only const inout data accessed
> m=c; // just loses guarantees to caller
> m=i; // ditto
> m=w; // ditto
> m=wc;// ditto
> w=wc;// m=c, c=c and i=i are valid
> wc=i;// c=i and i=i are valid
> wc=w;// c=m is not valid, but does the same thing as c=c here
> }
>
> If you disagree with one of them, please demonstrate how to
> break the type system using the conversion, or argue why a
> conversion would be valid.
I do agree with you on that one. However, c=m may be ok, as
nothing immutable can be muted. That is an open question.
inout don't make a lot of sense without return type. It needs to
be ironed out in that regard. Very good list !
More information about the Digitalmars-d
mailing list