www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4246] New: Delegate literals passed to variadic templates function incorrectly

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

           Summary: Delegate literals passed to variadic templates
                    function incorrectly
           Product: D
           Version: future
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: sandford jhu.edu



I found this while playing with delegate literals and map. Thankfully, map and
non-variadic templates don't compile with delegate literals, but this example
does:

import std.stdio: writeln;
import std.range;
import std.algorithm;

template bar(fun...) {
    auto bar(int[] r) {
        return fun[0](r.front);
    }
}

void main(string[] args) {
    int[] x = [1,2,3,4,5];
    int y = 6;

    auto dg = (int t){ return t + y; };

    auto list  = bar!( dg )(x);
    auto list2 = bar!( (int t){ return t + y; } )(x);
    writeln(list,'\t',list2);

    return;
}

This prints out the correct value (7) when a delegate is passed in, but the
delegate literal call results in a random printed number.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 28 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4246


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



I think this used to work:


import std.algorithm;
void main() {
    auto arr = [1, 2, 3];
    auto xr1 = map!("a * a")(arr); // OK
    auto xr2 = map!((int x){ return x * x; })(arr); // ERR
    auto xr3 = map!((x){ return x * x; })(arr); // ERR
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 28 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4246


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|D2                          |D1 & D2



Reduced test case. Applies to D1 also, as far back as DMD0.175.  Not a
regression.
-------------
int bug4246(fun...)() {
    return fun[0](7);
}

void main() {
    assert(  7 == bug4246!( (int t){ return t; } )()  );
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 16 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4246


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla kyllingen.net



*** Issue 4359 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 16 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4246


Don <clugdbug yahoo.com.au> changed:

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



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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 16 2010