Bug 19337 – [Reg 2.082.0] Cannot call std.algorithm.sort twice

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-10-27T13:10:36Z
Last change time
2018-11-08T05:22:16Z
Keywords
pull
Assigned to
No Owner
Creator
Jacob Carlborg

Comments

Comment #0 by doob — 2018-10-27T13:10:36Z
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 by greeenify — 2018-10-27T15:06:45Z
A temporary workaround is to do: arr.sort.release.sort
Comment #2 by iamthewilsonator — 2018-10-27T23:01:28Z
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 by code — 2018-11-04T18:22:54Z
Comment #4 by code — 2018-11-04T19:11:25Z
Comment #5 by github-bugzilla — 2018-11-08T05:22:15Z
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