| |
 | Posted by Jonathan M Davis | Permalink Reply |
|
Jonathan M Davis 
| http://d.puremagic.com/issues/show_bug.cgi?id=8368
Summary: std.algorithm.sort's template constraint is inadequate
Product: D
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody@puremagic.com
ReportedBy: jmdavisProg@gmx.com
--- Comment #0 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-07-10 00:24:37 PDT ---
This code fails to compile
import std.algorithm;
void main()
{
auto str = ["foo", "bar"].map!(x => x);
auto f = str.sort();
}
giving this string of errors
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7272): Error:
r[i2] is not an lvalue
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7273): Error:
r[i1] is not an lvalue
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7201): Error:
template instance std.algorithm.swapAt!(Result) error instantiating
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7285):
instantiated from here: getPivot!(binaryFun,Result)
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7034):
instantiated from here: sortImpl!(binaryFun,cast(SwapStrategy)0,Result)
q.d(8): instantiated from here: sort!("a <
b",cast(SwapStrategy)0,Result)
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7285): Error:
template instance std.algorithm.getPivot!(binaryFun,Result) error instantiating
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7034):
instantiated from here: sortImpl!(binaryFun,cast(SwapStrategy)0,Result)
q.d(8): instantiated from here: sort!("a <
b",cast(SwapStrategy)0,Result)
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7239): Error:
r[j] is not an lvalue
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7242): Error:
r[j] is not an lvalue
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7357): Error:
template instance std.algorithm.optimisticInsertionSort!(binaryFun,Result)
error instantiating
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7034):
instantiated from here: sortImpl!(binaryFun,cast(SwapStrategy)0,Result)
q.d(8): instantiated from here: sort!("a <
b",cast(SwapStrategy)0,Result)
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7034): Error:
template instance std.algorithm.sortImpl!(binaryFun,cast(SwapStrategy)0,Result)
error instantiating
q.d(8): instantiated from here: sort!("a <
b",cast(SwapStrategy)0,Result)
q.d(8): Error: template instance std.algorithm.sort!("a <
b",cast(SwapStrategy)0,Result) error instantiating
Clearly, sort's template constraint didn't properly catch the fact that the range being passed to map wouldn't compile with sort. sort fails to even test that the range is a random-access range! sort needs a proper template constraint which fails to compile with any range which won't work with it (either that or static asserts which give informative error messages when the type isn't going to work with sort). And some of the helper functions should probably have proper template constraints as well - e.g. the actual line that fails to compile is in swapAt, which has no template constraint.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
|