[Issue 21511] New: Uniqueness detection failed in non-template function with delegate parameter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 29 00:16:46 UTC 2020


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

          Issue ID: 21511
           Summary: Uniqueness detection failed in non-template function
                    with delegate parameter
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: qs.il.paperinik at gmail.com

immutable(int)* f(const scope int* function() pure @safe fp) @safe
{
    return fp(); // okay
}

immutable(int)* g(const scope int* delegate() pure @safe dg) @safe
{
    return dg(); // error
}

immutable(int)* h(DG)(const scope DG dg) @safe
    // just to be sure nothing surprising happens:
    if (is(DG == int* delegate() pure @safe))
{
    return dg(); // okay
}

The reason why the result of calling the function pointer or delegate are
valid, is due to uniqueness.[1] Especially weird is the fact that h lowers to g
after the template parameter is determined (only one option). Whether the
template parameter is given explicitly or is inferred from the argument is
irrelevant.

struct Test
{
    int* pureFunc() @safe pure;
    int* impureFunc() @safe;
}

@safe unittest
{
    Test test;
    auto p = h(&test.pureFunc); // okay
    auto q = h!(int* delegate() pure @safe)(&test.pureFunc); // also okay
}

[1] https://dlang.org/spec/const3.html#creating_immutable_data

--


More information about the Digitalmars-d-bugs mailing list