Placement of shared does not allow to set a delegate

Tolga Cakiroglu via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 16 09:37:27 PDT 2014


On Monday, 16 June 2014 at 15:25:51 UTC, Ali Çehreli wrote:
>
> Here is a minimal example that reproduces the issue and the 
> hint that compiles the code:
>
> class SocketListener
> {
>     public void delegate( shared(SocketListener) sender )
>     /* shared */    // <-- UNCOMMENT TO COMPILE
>     eventWhenStarted;
> }
>
> class C
> {
>     this()
>     {
>         auto listener = new shared SocketListener();
>         listener.eventWhenStarted = &listener_whenStarted;
>     }
>
>     public void listener_whenStarted( shared(SocketListener) 
> sender ) shared
>     {}
> }
>
> void main()
> {}
>
> Error: cannot implicitly convert expression 
> (&this.listener_whenStarted) of type void 
> delegate(shared(SocketListener) sender) shared to shared(void 
> delegate(shared(SocketListener)))
>
> Ali


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)))

---

Can this be a bug?


More information about the Digitalmars-d-learn mailing list