Bug 4901 – std.algorithm.sort does not compile for interfaces.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-09-20T05:44:00Z
Last change time
2010-12-17T10:32:41Z
Assigned to
andrei
Creator
schveiguy

Comments

Comment #0 by schveiguy — 2010-09-20T05:44:56Z
An assert meant to check the sort algorithm inadvertently makes it uncompilable for interfaces. reduced test case: import std.algorithm; interface I { @property int x(); } bool iless(I i1, I i2) { return i1.x < i2.x; } void main() { I[] x; std.algorithm.sort!iless(x); } outputs: /home/steves/dmd-2.049/linux/bin/../../src/phobos/std/conv.d(95): Error: template std.conv.toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) && isInputRange!(S) && isSomeChar!(ElementType!(S))) does not match any function template declaration /home/steves/dmd-2.049/linux/bin/../../src/phobos/std/conv.d(95): Error: template std.conv.toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) && isInputRange!(S) && isSomeChar!(ElementType!(S))) cannot deduce template function from argument types !(string)(I) /home/steves/dmd-2.049/linux/bin/../../src/phobos/std/conv.d(95): Error: template instance errors instantiating template /home/steves/dmd-2.049/linux/bin/../../src/phobos/std/conv.d(202): Error: template instance std.conv.to!(string).to!(I) error instantiating /home/steves/dmd-2.049/linux/bin/../../src/phobos/std/conv.d(95): instantiated from here: toImpl!(string,I[]) /home/steves/dmd-2.049/linux/bin/../../src/phobos/std/conv.d(3556): instantiated from here: to!(I[]) /home/steves/dmd-2.049/linux/bin/../../src/phobos/std/conv.d(3572): instantiated from here: textImpl!(string,string,string,I[]) /home/steves/dmd-2.049/linux/bin/../../src/phobos/std/algorithm.d(5187): instantiated from here: text!(string,string,I[]) testsort.d(16): instantiated from here: sort!(iless,cast(SwapStrategy)0,I[]) Line 5187 of std.algorithm is this: assert(isSorted!lessFun(r), text(Range.stringof, ": ", r));
Comment #1 by schveiguy — 2010-12-17T10:32:41Z