www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9152] New: Regression in type inference of array of delegates

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9152

           Summary: Regression in type inference of array of delegates
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: hsteoh quickfur.ath.cx



This code used to compile in 2.058:

        alias void delegate(int) DgType;

        void dispatch(DgType[] funcTable, int idx, int arg) {
                funcTable[idx](arg);
        }

        void main() {
                dispatch([
                        (int x) { return x+x; },
                        (int x) { return x*x; },
                        (int x) { return x^^2; }
                ], 0, 1);
        }

Since 2.059, dmd is unable to correctly infer the type of the delegate array
literal:

        test.d(9): Error: function test.dispatch (void delegate(int)[]
funcTable, int idx, int arg) is not callable using argument types (int
function(int x) pure nothrow  safe[],int,int)
        test.d(9): Error: cannot implicitly convert expression ([delegate pure
nothrow  safe int(int x)
        {
        return x + x;
        }
        , delegate pure nothrow  safe int(int x)
        {
        return x * x;
        }
        , delegate pure nothrow  safe int(int x)
        {
        return int __powtmp8 = x;
         , __powtmp8 * __powtmp8;
        }
        ]) of type int function(int x) pure nothrow  safe[] to void
delegate(int)[]


In this case, one can add  safe to the alias as a workaround, but it doesn't
work if the same function needs to be called with another array that contains a
 system delegate.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 13 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9152


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



Oops, the code snippet is wrong. I'll have to reduce the actual failing code
again and file another bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 13 2012