www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4842] New: Wrong code with template literals

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

           Summary: Wrong code with template literals
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dsimcha yahoo.com



The following code was written for Rosetta Code and is intended to find all
factors of an integer.  It produces wrong results.  The exact wrong results
depend on whether inlining is enabled.

import std.range, std.algorithm, std.stdio;

auto factors(I)(I num) {
    return filter!((i) { return num % i == 0; })(
        iota(1, num + 1)
    );
}

void main() {
    writeln(factors(36));
}


If I change the line with the lambda from a template literal to a delegate
literal:

return filter!((I i) { return num % i == 0; })

then it works.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 08 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4842


David Simcha <dsimcha yahoo.com> changed:

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



Can't reproduce this anymore.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 12 2011