inout delegate
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Sun Oct 2 09:30:01 PDT 2016
On 02.10.2016 18:00, Steven Schveighoffer wrote:
> On 10/2/16 2:55 AM, Manu via Digitalmars-d wrote:
>> Can someone explain this to me?
>>
>> class Test
>> {
>> inout(int) f() inout { return 10; }
>>
>> void t()
>> {
>> f(); // calls fine with mutable 'this'
>> auto d = &this.f; // error : inout method Test.f is not callable
>> using a mutable this
>> d();
>> }
>> }
>>
>> That error message seems very unhelpful, and it's not true. Of course
>> an inout method is callable with a mutable 'this'...
>>
>> I suspect that the problem is the type for the delegate; "inout(int)
>> delegate()" doesn't leave anything for the type system to resolve the
>> inout with.
>> I guess the expectation is that this delegate has it's inout-ness
>> resolved when you capture the delegate:
>> is(typeof(&this.f) == int delegate())
>> Or if 'this' were const:
>> is(typeof(&this.f) == const(int) delegate())
>
> I think this is a bug, and I 100% agree with you. The type of the
> delegate should be based on the mutability of 'this'.
>
> The error message probably stems from logic that was meant to prevent
> invalid const/immutable delegate capture, but inout wasn't thought of.
>
> -Steve
Definitely a bug. (My frontend implementation accepts the code and
correctly determines the delegate type as 'int delegate()'.)
More information about the Digitalmars-d
mailing list