DIP30, delegates more destruction for your pleasure

Timon Gehr timon.gehr at gmx.ch
Thu Mar 14 04:42:28 PDT 2013


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?

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.


More information about the Digitalmars-d mailing list