Bug 7708 – cannot implicitly assign delegate taking const to a delegate reference taking mutable
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-14T09:35:00Z
Last change time
2013-11-26T20:33:25Z
Assigned to
nobody
Creator
govellius
Comments
Comment #0 by govellius — 2012-03-14T09:35:03Z
main()
{
alias int delegate( const int[] ) A;
alias int delegate( int[] ) B;
A a;
B b = cast(B) a; // OK
B b2 = a; // Error: cannot implicitly convert expression (a) of type
// int delegate(const(int[])) to int delegate(int[])
}
I think the cast is unnecessary, (b) should be allowed to point to a delegate of type (A) as well.
Comment #1 by turkeyman — 2012-04-22T16:20:16Z
I think you might have this around the wrong way...
Comment #2 by govellius — 2012-04-23T07:16:50Z
void main()
{
alias int delegate( const int[] ) A;
alias int delegate( int[] ) B;
int c_func( const int[] arg ) { return arg[0]; }
int m_func( int[] arg ) { return arg[0] = 0; }
const int[] ci = [ 1,2,3 ];
int[] mi = [ 4,5,6 ];
A a = &c_func;
a( ci );
a( mi );
B b = &m_func;
// b( ci ); Error ( good )
b( mi );
/* b = &c_func;
Error: cannot implicitly convert expression (&c_func)
of type int delegate(const(int[]))
to int delegate( int[] )
*/
b = cast(B) &c_func; // Forced to cast
// Even though b really points to c_func;
// It has to be a type error to attempt it
// b( ci ); Error ( good )
b( mi );
}
if b() can point to a function that mutates it's argument
why can't it point to a function that does not mutate it's argument?
Comment #3 by yebblies — 2013-11-26T20:33:25Z
*** This issue has been marked as a duplicate of issue 3075 ***