Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 02, 2016 Re: inout delegate | ||||
---|---|---|---|---|
| ||||
And what's the logic behind this: class Test { int f() { return 10; } static assert(is(typeof(&typeof(this).f) == int function())); // huh? static void t() { // as expected: f(); // error : need 'this' for 'f' of type 'int()' // calling a method without a context pointer... auto x = &f; x(); // call the method with no context pointer, how is this okay? pragma(msg, typeof(x)); // prints: int function() } } If f() were supplied an argument, the function would receive the first arg as the context pointer, and the rest would be out by 1! O_o I don't see how this code can be acceptable? If such a thing (getting a static function pointer from a delegate) were to be supported, surely: is(typeof(&Test.f) == int function(Test)), though this is only valid for some (most) abi's. On 2 October 2016 at 19:55, Manu <turkeyman@gmail.com> 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()) > > But I get this unhelpful error instead. > > What's the story here? |
October 02, 2016 Re: inout delegate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On 02.10.2016 13:27, Manu via Digitalmars-d wrote: > And what's the logic behind this: > > class Test > { > int f() { return 10; } > > static assert(is(typeof(&typeof(this).f) == int function())); // huh? > > static void t() > { > // as expected: > f(); // error : need 'this' for 'f' of type 'int()' > > // calling a method without a context pointer... > auto x = &f; > x(); // call the method with no context pointer, how is this okay? > > pragma(msg, typeof(x)); // prints: int function() > } > } > > If f() were supplied an argument, the function would receive the first > arg as the context pointer, and the rest would be out by 1! O_o > I don't see how this code can be acceptable? > > If such a thing (getting a static function pointer from a delegate) > were to be supported, surely: is(typeof(&Test.f) == int > function(Test)), though this is only valid for some (most) abi's. This is a known issue: https://issues.dlang.org/show_bug.cgi?id=3720 (What I do is: typeof(&typeof(this).f) is int delegate(), but auto x = &f does not compile as the 'this' reference is missing.) |
October 03, 2016 Re: inout delegate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On 3 October 2016 at 02:37, Timon Gehr via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> On 02.10.2016 13:27, Manu via Digitalmars-d wrote:
>>
>> And what's the logic behind this:
>>
>> class Test
>> {
>> int f() { return 10; }
>>
>> static assert(is(typeof(&typeof(this).f) == int function())); // huh?
>>
>> static void t()
>> {
>> // as expected:
>> f(); // error : need 'this' for 'f' of type 'int()'
>>
>> // calling a method without a context pointer...
>> auto x = &f;
>> x(); // call the method with no context pointer, how is this okay?
>>
>> pragma(msg, typeof(x)); // prints: int function()
>> }
>> }
>>
>> If f() were supplied an argument, the function would receive the first
>> arg as the context pointer, and the rest would be out by 1! O_o
>> I don't see how this code can be acceptable?
>>
>> If such a thing (getting a static function pointer from a delegate)
>> were to be supported, surely: is(typeof(&Test.f) == int
>> function(Test)), though this is only valid for some (most) abi's.
>
>
> This is a known issue: https://issues.dlang.org/show_bug.cgi?id=3720
>
> (What I do is: typeof(&typeof(this).f) is int delegate(), but auto x = &f
> does not compile as the 'this' reference is missing.)
It compiles for me... (using yesterday's nightly)
I pasted it right from my code.
|
October 03, 2016 Re: inout delegate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On Monday, 3 October 2016 at 02:47:09 UTC, Manu wrote:
> On 3 October 2016 at 02:37, Timon Gehr via Digitalmars-d
>> This is a known issue: https://issues.dlang.org/show_bug.cgi?id=3720
>>
>> (What I do is: typeof(&typeof(this).f) is int delegate(), but auto x = &f
>> does not compile as the 'this' reference is missing.)
>
> It compiles for me... (using yesterday's nightly)
> I pasted it right from my code.
It wouldn't compile using Timon's frontend, which was his point.
— David
|
Copyright © 1999-2021 by the D Language Foundation