On 06/16/2014 09:37 AM, Tolga Cakiroglu wrote:

> On Monday, 16 June 2014 at 15:25:51 UTC, Ali Çehreli wrote:

> Okay, now I continue with another thing. After defining the event
> attribute as follows
>
> public void delegate( shared(SocketListener) sender ) shared
> eventWhenStarted;
>
>
> ---
>
>
> I removed the "shared" keyword from that method
>
> public void listener_whenStarted( shared(SocketListener) sender ){}
>
>
> ---
>
>
> Then set the attribute as follows
>
> listener.eventWhenStarted = cast(shared)(&listener_whenStarted);
>
>
> ---
>
>
> There is error again.
>
> main.d(21): Error: cannot implicitly convert expression
> (&this.listener_whenStarted) of type shared(void
> delegate(shared(SocketListener))) to shared(void
> delegate(shared(SocketListener)))
>
> ---
>
> This error is important, because both types are completely same:
>
> main.d(21): Error: cannot implicitly convert expression
> (&this.listener_whenStarted) of type
>
> shared(void delegate(shared(SocketListener)))
> to
> shared(void delegate(shared(SocketListener)))

The second type is different with dmd 2.066:

Error: cannot implicitly convert expression (&this.listener_whenStarted) of type

shared(void delegate(shared(SocketListener)))
to
shared(void delegate(shared(SocketListener)) shared)

However, I may have misunderstood your description. This is the code I tried:

class SocketListener
{
public void delegate( shared(SocketListener) sender ) shared eventWhenStarted;
}

class C
{
    this()
    {
        auto listener = new shared SocketListener();
        listener.eventWhenStarted = cast(shared)&listener_whenStarted;
    }

    public void listener_whenStarted( shared(SocketListener) sender )
    {}
}

void main()
{}

> ---
>
> Can this be a bug?

I don't know but I theorize like this: :) There are three 'shared' qualifiers in the last error message.

shared(void delegate(shared(SocketListener)) shared)

1) The 'shared' in the middle: That one makes the delegate take a shared(SocketListener) argument when it gets called.

2) The 'shared' on the right-hand side: (I am not sure about this one.) That one makes the context pointer of the delegate 'shared'. For example, the delegate can only be called on a shared class object.

3) The 'shared' on the left-hand side: That one makes the type of the delegate shared so that e.g. such a delegate can be passed between threads.

That's what I understand.

Ali

Reply via email to