D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7708 - cannot implicitly assign delegate taking const to a delegate reference taking mutable
Summary: cannot implicitly assign delegate taking const to a delegate reference taking...
Status: RESOLVED DUPLICATE of issue 3075
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-14 09:35 UTC by Shahid
Modified: 2013-11-26 20:33 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Shahid 2012-03-14 09:35:03 UTC
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 Manu 2012-04-22 16:20:16 UTC
I think you might have this around the wrong way...
Comment 2 Shahid 2012-04-23 07:16:50 UTC
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 yebblies 2013-11-26 20:33:25 UTC

*** This issue has been marked as a duplicate of issue 3075 ***