[Issue 17084] New: Can't sort array of structs with alias this: swap can't call non- at nogc function doesPointTo
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Jan 10 23:00:03 PST 2017
https://issues.dlang.org/show_bug.cgi?id=17084
Issue ID: 17084
Summary: Can't sort array of structs with alias this: swap
can't call non- at nogc function doesPointTo
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: dhasenan at gmail.com
I have no clue what's going on.
Dustmite-minimized with some hand massaging:
---
import std.algorithm;
struct URL
{
int[] queryParams;
string toString() const { return ""; }
alias toString this;
}
struct Page
{
URL url;
int opCmp(Page) { return 0; }
}
void main()
{
Page[] s;
std.algorithm.sort(s);
}
---
Removing 'alias this' fixes it. Making 'queryParams' not be an array fixes it.
(But putting the array in another struct does not.) Inlining the struct fixes
the error (incorporating the fields and methods from URL into Page).
Error:
---
/usr/include/dmd/phobos/std/algorithm/mutation.d(2183): Error: @nogc function
'std.algorithm.mutation.swap!(Page).swap' cannot call non- at nogc function
'std.exception.doesPointTo!(Page, Page, void).doesPointTo'
/usr/include/dmd/phobos/std/algorithm/mutation.d(2184): Error: @nogc function
'std.algorithm.mutation.swap!(Page).swap' cannot call non- at nogc function
'std.exception.doesPointTo!(Page, Page, void).doesPointTo'
/usr/include/dmd/phobos/std/algorithm/mutation.d(2185): Error: @nogc function
'std.algorithm.mutation.swap!(Page).swap' cannot call non- at nogc function
'std.exception.doesPointTo!(Page, Page, void).doesPointTo'
/usr/include/dmd/phobos/std/algorithm/mutation.d(2186): Error: @nogc function
'std.algorithm.mutation.swap!(Page).swap' cannot call non- at nogc function
'std.exception.doesPointTo!(Page, Page, void).doesPointTo'
/usr/include/dmd/phobos/std/algorithm/mutation.d(2009): Error: template
instance std.algorithm.mutation.swap!(Page) error instantiating
/usr/include/dmd/phobos/std/algorithm/sorting.d(1322): instantiated from
here: swapAt!(Page[])
/usr/include/dmd/phobos/std/algorithm/sorting.d(1293): instantiated from
here: siftDown!()
/usr/include/dmd/phobos/std/algorithm/sorting.d(1278): instantiated from
here: buildHeap!()
/usr/include/dmd/phobos/std/algorithm/sorting.d(1217): instantiated from
here: heapSort!()
/usr/include/dmd/phobos/std/algorithm/sorting.d(1047): instantiated from
here: quickSortImpl!(binaryFun, Page[])
server.d(19): instantiated from here: sort!("a < b",
cast(SwapStrategy)0, Page[])
/usr/include/dmd/phobos/std/algorithm/sorting.d(1283): Error: template instance
std.algorithm.sorting.HeapOps!(binaryFun, Page[]).percolate!() error
instantiating
/usr/include/dmd/phobos/std/algorithm/sorting.d(1217): instantiated from
here: heapSort!()
/usr/include/dmd/phobos/std/algorithm/sorting.d(1047): instantiated from
here: quickSortImpl!(binaryFun, Page[])
server.d(19): instantiated from here: sort!("a < b",
cast(SwapStrategy)0, Page[])
/usr/include/dmd/phobos/std/algorithm/sorting.d(1222): Error: template instance
std.algorithm.sorting.getPivot!(binaryFun, Page[]) error instantiating
/usr/include/dmd/phobos/std/algorithm/sorting.d(1047): instantiated from
here: quickSortImpl!(binaryFun, Page[])
server.d(19): instantiated from here: sort!("a < b",
cast(SwapStrategy)0, Page[])
Failed: ["dmd", "-v", "-o-", "server.d", "-I."]
---
--
More information about the Digitalmars-d-bugs
mailing list