www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21511] New: Uniqueness detection failed in non-template


          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 puremagic.com
          Reporter: qs.il.paperinik 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

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

Dec 28 2020