[Issue 17084] Can't sort array of structs with alias this: swap can't call non- at nogc function doesPointTo

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 22 10:14:00 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=17084

Basile B. <b2.temp at gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp at gmx.com
           Hardware|x86_64                      |All
                 OS|Windows                     |All

--- Comment #1 from Basile B. <b2.temp at gmx.com> ---
making `URL.toString()` `@nogc` or making `URL.toString` a parameter-less
function template also fixes it.

Curiously, if you put this in std.exception:

```d
@safe @nogc unittest
{
    import std.algorithm;

    static struct URL
    {
        int[] queryParams;
        string toString() const { return ""; }
        alias toString this;
    }

    static struct Page
    {
        URL url;
        int opCmp(Page) { return 0; }
    }

    Page[] s;
    std.algorithm.sort(s);
}
```

and call 

```shell
dmd exception.d -unittest -main -oftest && ./test
```

Then it works directly, i.e no need to do anything.

Finally a last way to make it working is to explicitly annotate `doesPointTo()`
as `@nogc`. Looking at `doesPointTo` implementation you can verify that it's
indeed `@nogc` (just a small change to make for static arrays) so this solution
can be a candidate for a PR (i'll try to propose), until better is found.

This issue could rather be a compiler one, e.g a bit like the one where
inference of attribute fails when there are mutual calls.

--


More information about the Digitalmars-d-bugs mailing list