[Issue 16572] New: can't take inout delegate

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Oct 2 03:43:49 PDT 2016


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

          Issue ID: 16572
           Summary: can't take inout delegate
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: turkeyman at gmail.com

class Test
{
  inout(int) f() inout { return 10; }
  const(int) g() const { return 10; }

  void t()
  {
    f(); // can call just fine with mutable 'this'
    auto d = &this.f; // error : inout method Test.f is not callable using a
mutable this
    d();
    auto e = &this.g; // no problem
    e();
  }
}

Other than the fact that I find this error message terribly misleading, I also
don't think this situation is okay.
It's a terrible edge-case. Are we to say "unlike const, immutable; inout
methods can not be captured as delegates"?

I guess the only reasonable solution here is to 'resolve' the inout-ness at the
delegate capture?

--


More information about the Digitalmars-d-bugs mailing list