D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4842 - Wrong code with template literals
Summary: Wrong code with template literals
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-09-08 20:02 UTC by David Simcha
Modified: 2011-08-12 20:45 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2010-09-08 20:02:38 UTC
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.
Comment 1 David Simcha 2011-08-12 20:45:54 UTC
Can't reproduce this anymore.