http://d.puremagic.com/issues/show_bug.cgi?id=10709
Summary: reduce 1-function + no seed, wrong type inference
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: rejects-valid
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from [email protected] 2013-07-23 23:57:27 PDT ---
When reduce is not given a seed, it takes the ranges "front" as a first
element, however, seed's type should be that of the result of calling "fun".
This is relevent for a function for example, that takes int, and returns a
double, or a function that takes operates on const(char)[], and is passed a
string: In both case, reduce will error out when trying to store the result (eg
double) into the seed (eg int).
What is interesting is that "reduce!fun" gets it wrong, but "reduce!(fun,
fun...)" gets it right.
//----
import std.stdio, std.algorithm;
void main(string[] args)
{
{
enum foo = "a + 0.5 * b";
auto r = [0, 1, 2, 3];
//auto r1 = reduce!foo(r); //<-- HERE
auto r2 = reduce!(foo, foo,)(r);
//writeln(r1);
writeln(r2);
}
{
const(char)[] foo(const(char)[], const(char)[]);
string[] r = ["hello", "world"];
//auto r1 = reduce!foo(r); //<-- HERE
auto r2 = reduce!(foo, foo,)(r);
//writeln(r1);
writeln(r2);
}
}
//----
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------