D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4901 - std.algorithm.sort does not compile for interfaces.
Summary: std.algorithm.sort does not compile for interfaces.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-20 05:44 UTC by Steven Schveighoffer
Modified: 2010-12-17 10:32 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 Steven Schveighoffer 2010-09-20 05:44:56 UTC
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 Steven Schveighoffer 2010-12-17 10:32:41 UTC
Fixed in svn : http://www.dsource.org/projects/phobos/changeset/2226