D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19337 - [Reg 2.082.0] Cannot call std.algorithm.sort twice
Summary: [Reg 2.082.0] Cannot call std.algorithm.sort twice
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2018-10-27 13:10 UTC by Jacob Carlborg
Modified: 2018-11-08 05:22 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jacob Carlborg 2018-10-27 13:10:36 UTC
The following example worked with DMD 2.081.0 but fails to compile with 2.082.0 and later:

import std.algorithm;

void main()
{
    [1, 2,].sort.sort;
}

The error message is:

phobos/std/algorithm/sorting.d(1877): Error: cannot implicitly convert expression assumeSorted(r) of type SortedRange!(int[], "a < b") to SortedRange!(SortedRange!(int[], "a < b"), "a < b")
main.d(5): Error: template instance `std.algorithm.sorting.sort!("a < b", cast(SwapStrategy)0, SortedRange!(int[], "a < b"))` error instantiating
Comment 1 Seb 2018-10-27 15:06:45 UTC
A temporary workaround is to do:

arr.sort.release.sort
Comment 2 Nicholas Wilson 2018-10-27 23:01:28 UTC
Looks like something like https://github.com/dlang/phobos/blob/master/std/complex.d#L656 would help here.

/*  Makes Complex!(Complex!T) fold to Complex!T.
    The rationale for this is that just like the real line is a
    subspace of the complex plane, the complex plane is a subspace
    of itself.  Example of usage:
    ---
    Complex!T addI(T)(T x)
    {
        return x + Complex!T(0.0, 1.0);
    }
    ---
    The above will work if T is both real and complex.
*/
template Complex(T)
if (is(T R == Complex!R))
{
    alias Complex = T;
}
Comment 3 Martin Nowak 2018-11-04 18:22:54 UTC
This was introduced by https://github.com/dlang/phobos/pull/6535.
Comment 4 Martin Nowak 2018-11-04 19:11:25 UTC
PR: https://github.com/dlang/phobos/pull/6748
Comment 5 github-bugzilla 2018-11-08 05:22:15 UTC
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/a8e9857756e1b1db5735c31c2085569c95a7d6e6
fix Issue 19337 - cannot call std.algorithm.sort twice

- introduced with #6535 which stripped nested SortedRange types
  in assumeSorted, thus causing a mismatch between the return type
  of sort (SortedRange!(SortedRange!R)) and assumeSorted SortedRange!R
- fix by stripping nested SortedRange types in the SortedRange!R
  template instantiation

https://github.com/dlang/phobos/commit/ef206af1a0ae841724a38682d1e0073e631d4b3d
Merge pull request #6748 from MartinNowak/fix19337

fix Issue 19337 - cannot call std.algorithm.sort twice