DMD 2.055
bearophile
bearophileHUGS at lycos.com
Thu Sep 8 04:29:02 PDT 2011
Johannes Pfau:
> I assume the problem is in line 22 of the code you posted? As a
> workaround, try to explicitly cast the delegates to the same type:
>
> [cast(string delegate(string))(string text) { return toLower(text); },
> cast(string delegate(string))(string text) { return wipeOutChars(text,subchars); },
> cast(string delegate(string))(string text) { return removeSpaces(text); } ]
Casts are dangerous. I think you are stripping away a @system.
This is reduced code that shows the OP problem:
int foo(int s) pure @safe {
return 0;
}
int bar(int s) @system {
return 1;
}
void main() {
auto A = [(int x){ return foo(x); },
(int x){ return bar(x); }];
auto B = [cast(int delegate(int) @system)(int x){ return foo(x); },
cast(int delegate(int) @system)(int x){ return bar(x); }];
}
With DMD 2.055:
test.d(9): Error: incompatible types for ((__dgliteral1) ? (__dgliteral2)): 'int delegate(int x) pure' and 'int delegate(int x) @system'
In my opinion the compiler has to use the most general type for A, avoiding the casts used in B. Do you know if this in Bugzilla already, and its entry number?
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list