Bug 13304 – std.algorithm.reduce: "Unable to deduce an acceptable seed type" with float[]

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-08-15T23:25:00Z
Last change time
2014-10-04T22:00:21Z
Keywords
rejects-valid
Assigned to
nobody
Creator
dlang-bugzilla

Comments

Comment #0 by dlang-bugzilla — 2014-08-15T23:25:42Z
/////////////////// test.d /////////////////// import std.algorithm; void main() { float[] nums; float sum = reduce!((a,b) => a + b)(nums); } ////////////////////////////////////////////// Introduced in https://github.com/D-Programming-Language/phobos/pull/2060
Comment #1 by monarchdodra — 2014-08-16T09:24:51Z
(In reply to Vladimir Panteleev from comment #0) > /////////////////// test.d /////////////////// > import std.algorithm; > > void main() > { > float[] nums; > float sum = reduce!((a,b) => a + b)(nums); > } > ////////////////////////////////////////////// > > Introduced in https://github.com/D-Programming-Language/phobos/pull/2060 Seems its a glitch in the way the assertion code is written. The good news is there is no logical fallacy in the algorithm. I'll give it a quick fix.
Comment #2 by monarchdodra — 2014-08-16T09:56:28Z
(In reply to monarchdodra from comment #1) > I'll give it a quick fix. It turns out there is something that is making the compiler complain in my tests, because it is trying to *actually* evaluate the predicate in test (rather than just check compilability). This triggers it, because it complains it has no access to source code. What's funny is that it works fine with string predicate: float sum = reduce!(binaryFun!"a + b")(nums); //OK! float sum = reduce!((a,b) => a + b)(nums); //NOPE! This is weird. I wonder if there isn't another related regression or something. I'm gonna try to reduce.
Comment #3 by monarchdodra — 2014-08-16T10:08:15Z
OK: Is this a rejects valid? //---- import std.functional; void main(string[] args) { foo!(binaryFun!"a + b")(); foo!((a,b) => a + b)(); } void foo(alias pred)() { alias A = Test1!int.Test2!pred; } template Test1(E) { template Test2(alias pred) { } } //---- Error: template instance Test2!(__lambda2) cannot use local '__lambda2' as parameter to non-global template Test2(alias pred) Error: template instance main.main.foo!((a, b) => a + b) error instantiating It doesn't quite explain the issue, but it still seems strange to me. my lambda doesn't require context, so it shouldn't considered "local", should it? Also, I don't understand the issue about "Global" template.
Comment #4 by dlang-bugzilla — 2014-08-16T12:53:07Z
(In reply to monarchdodra from comment #3) > Error: template instance Test2!(__lambda2) cannot use local '__lambda2' as > parameter to non-global template Test2(alias pred) > Error: template instance main.main.foo!((a, b) => a + b) error instantiating Try adding "static" to Test1 or Test2. Probably related to issue 11946. > It doesn't quite explain the issue, but it still seems strange to me. my > lambda doesn't require context, so it shouldn't considered "local", should > it? Also, I don't understand the issue about "Global" template. Yes, doesn't seem right. File it and maybe Kenji will look at it.
Comment #5 by code — 2014-10-04T20:59:49Z
Any fix in sight?
Comment #6 by monarchdodra — 2014-10-04T22:00:21Z
(In reply to Martin Nowak from comment #5) > Any fix in sight? Sorry, the issue is fixed. https://github.com/D-Programming-Language/phobos/pull/2431 I still need to file the "Global template" issue though.