Casting between delegates with qualified value type parameters

Sean Eskapp eatingstaples at gmail.com
Thu Jan 20 09:31:39 PST 2011


Delegates cannot be cast from one type to another, even if the only difference
in type is the qualifiers on value type parameters. However, the same code
works fine with functions instead of delegates, as such:

import std.stdio;

void foo(void function(int) bar)
{
	bar(5);
}

void foobar(void delegate(int) bar)
{
	bar(5);
}

void main()
{
	foo   (function(int i)           { writeln(i); }); // OK
	foo   (function(immutable int i) { writeln(i); }); // OK
	foobar(delegate(int i)           { writeln(i); }); // OK
	foobar(delegate(immutable int i) { writeln(i); }); // error
}


Is there a reason for this, or is it a bug?


More information about the Digitalmars-d mailing list