D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21183 - schwartzSort does not strip const
Summary: schwartzSort does not strip const
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 minor
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-08-21 10:28 UTC by FeepingCreature
Modified: 2020-08-21 16:43 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 FeepingCreature 2020-08-21 10:28:40 UTC
Consider the following code:

import std.algorithm : schwartzSort;
import std.array : array;

struct S
{
    int i;
    const(int) foo() { return i; }
}

void main()
{
    auto list = [S(4), S(3), S(2)];
    assert(list.dup.schwartzSort!(a => a.foo).array == [S(2), S(3), S(4)]);
}

This leads to cryptic errors due to the fact that `schwartzSort` does not strip the `const` from `const(int)` for its internal array, even though it trivially could since it's a value type.
Comment 1 Dlang Bot 2020-08-21 12:26:58 UTC
@MoonlightSentinel created dlang/phobos pull request #7602 "Fix Issue 21183 - schwartzSort does not strip const" fixing this issue:

- Fix Issue 21183 - schwartzSort does not strip const
  
  Fixed by using the unqualified type if possible

https://github.com/dlang/phobos/pull/7602
Comment 2 Dlang Bot 2020-08-21 16:43:14 UTC
dlang/phobos pull request #7602 "Fix Issue 21183 - schwartzSort does not strip const" was merged into stable:

- 255f9496d1ef72876613d27341dee483e364aa3d by MoonlightSentinel:
  Fix Issue 21183 - schwartzSort does not strip const
  
  Fixed by using the unqualified type if possible

https://github.com/dlang/phobos/pull/7602