[Issue 20116] New: Cannot return inout return value from delegate

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 8 16:27:31 UTC 2019


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

          Issue ID: 20116
           Summary: Cannot return inout return value from delegate
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: htvennik at gmail.com

Template function wrapping a delegate fails when the delegate happens to return
an inout type.

----

import std.traits : Parameters, ReturnType;

class C
{
    private int[] _arr;

    @property auto arr() inout nothrow @nogc @safe
    {
        return _arr;
    }
}

ReturnType!DG foo(DG)(scope DG func)
if (!is(ReturnType!DG == void) && 0 == Parameters!func.length)
{
    return func();
}

void main()
{
    C c;
    foo(&c.arr);
}

----

inout.d(51): Error: inout on return means inout must be on a parameter as well
for ReturnType!(inout(int[]) delegate() inout nothrow @nogc @property
@safe)(scope DG func)
inout.d(60): Error: template instance `inout.foo!(inout(int[]) delegate() inout
nothrow @nogc @property @safe)` error instantiating

--


More information about the Digitalmars-d-bugs mailing list