October 22, 2018 Re: need help about get all public static function name | ||||
---|---|---|---|---|
| ||||
Posted in reply to test | On Monday, 22 October 2018 at 12:03:22 UTC, test wrote:
> On Monday, 22 October 2018 at 11:59:21 UTC, test wrote:
>> On Monday, 22 October 2018 at 11:42:59 UTC, test wrote:
>> I try made a simple example but it has no error:
>
>
> I find the way to show the error:
>
> https://run.dlang.io/is/f8cULz
>
>
> import std.traits;
>
> struct FiberS {
> static auto getThis(){
> return Fiber.getId();
> }
> }
>
> struct Proxy(T){
> T* ptr;
> alias getPayload this;
>
> @property ref auto getPayload() inout return {
> return * ptr ;
> }
>
> static auto getId(){
> return 1;
> }
> }
> alias Fiber = Proxy!(FiberS);
>
>
> extern(C) void main(){
> auto id = Fiber.getThis(); // work here
> }
>
> struct TcpStream {
> void read(ubyte[] data){
> auto id = Fiber.getThis(); // not work here in my case
> }
> }
Let's analyze this call:
auto id = Fiber.getThis();
You're trying to call a static function 'getThis' on Fiber.
The type 'Fiber' is really a Proxy!FiberS. Proxy doesn't have a static getThis() function. So the compiler tries an 'alias this', which forwards to a non-static member function getPayload(). To call that function, you need an instance of 'Proxy', which you don't have.
I guess the first error message ("this for getPayload needs to be type Proxy not type TcpStream") just doesn't report that clearly.
|
October 22, 2018 Re: need help about get all public static function name | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stanislav Blinov | On Monday, 22 October 2018 at 12:16:50 UTC, Stanislav Blinov wrote: > On Monday, 22 October 2018 at 12:03:22 UTC, test wrote: > You're trying to call a static function 'getThis' on Fiber. > The type 'Fiber' is really a Proxy!FiberS. Proxy doesn't have a static getThis() function. So the compiler tries an 'alias this', which forwards to a non-static member function getPayload(). To call that function, you need an instance of 'Proxy', which you don't have. > I guess the first error message ("this for getPayload needs to be type Proxy not type TcpStream") just doesn't report that clearly. But this work: > extern(C) void main(){ > auto id = Fiber.getThis(); // work here > } here also dont have Fiber instance. |
October 22, 2018 Re: need help about get all public static function name | ||||
---|---|---|---|---|
| ||||
Posted in reply to test | On Monday, 22 October 2018 at 12:32:57 UTC, test wrote:
> On Monday, 22 October 2018 at 12:16:50 UTC, Stanislav Blinov wrote:
>> On Monday, 22 October 2018 at 12:03:22 UTC, test wrote:
>> You're trying to call a static function 'getThis' on Fiber.
>> The type 'Fiber' is really a Proxy!FiberS. Proxy doesn't have a static getThis() function. So the compiler tries an 'alias this', which forwards to a non-static member function getPayload(). To call that function, you need an instance of 'Proxy', which you don't have.
>> I guess the first error message ("this for getPayload needs to be type Proxy not type TcpStream") just doesn't report that clearly.
>
>
> But this work:
>
>> extern(C) void main(){
>> auto id = Fiber.getThis(); // work here
>> }
>
> here also dont have Fiber instance.
I think this is a bug.
If I use "alias this " with a FiberS instance tuple memebr, it will work. but if I use alias this with @propery , it only work on static method, on delegate method it will use delegate this.
This is kind like Javascript method this is come from caller place. I think it is a bug. please help me confirm this. If so please made a bug report for me.
|
Copyright © 1999-2021 by the D Language Foundation