Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
September 02, 2011 Re: Copying a variable state in a delegate literal definition | ||||
---|---|---|---|---|
| ||||
Damn it looks like I've ran into some template bug as well. With this: @property void connect(Signal signal = Signal.MouseClick)(void delegate() dg) { clickHandlers ~= dg; } and a call like this: item.connect = { this.showMenu(0); }; this crashes with an access violation. But if I change connect to be a regular function: @property void connect(void delegate() dg) { clickHandlers ~= dg; } Then it works properly. Hmmm... |
September 02, 2011 Re: Copying a variable state in a delegate literal definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 09/02/2011 08:46 PM, Andrej Mitrovic wrote:
> Damn it looks like I've ran into some template bug as well.
>
> With this:
> @property void connect(Signal signal = Signal.MouseClick)(void
> delegate() dg)
> {
> clickHandlers ~= dg;
> }
>
> and a call like this:
> item.connect = { this.showMenu(0); };
>
> this crashes with an access violation. But if I change connect to be a
> regular function:
> @property void connect(void delegate() dg)
> {
> clickHandlers ~= dg;
> }
>
> Then it works properly. Hmmm...
What happens if you declare the function final?
|
September 02, 2011 Re: Copying a variable state in a delegate literal definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On 9/3/11, Timon Gehr <timon.gehr@gmx.ch> wrote:
> What happens if you declare the function final?
Doesn't help. But it has to be virtual as every object needs to have it's own set of delegates.
And wow, it seems to be random as well. If I do this:
@property void connect(Signal signal = Signal.MouseClick)(void
delegate() dg)
{
writeln(&dg);
clickHandlers ~= dg;
}
It won't crash. But if I comment out the writeln() call it crashes with an access violation. I've tested this a few dozen times. This definitely looks like a compiler bug. But I have to reduce it first before I file it.
|
September 02, 2011 Re: Copying a variable state in a delegate literal definition | ||||
---|---|---|---|---|
| ||||
On 9/3/11, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
> On 9/3/11, Timon Gehr <timon.gehr@gmx.ch> wrote:
>> What happens if you declare the function final?
>
> Doesn't help. But it has to be virtual as every object needs to have it's own set of delegates.
Erm, sorry that reasoning was wrong. The function is defined once in an abstract class and can be final, absolutely.
|
September 02, 2011 Re: Copying a variable state in a delegate literal definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 09/03/2011 01:13 AM, Andrej Mitrovic wrote: > On 9/3/11, Timon Gehr<timon.gehr@gmx.ch> wrote: >> What happens if you declare the function final? > > Doesn't help. But it has to be virtual as every object needs to have > it's own set of delegates. So if I get you right, you made the templated version final? Did you try making the non-templated version final? > > And wow, it seems to be random as well. If I do this: > > @property void connect(Signal signal = Signal.MouseClick)(void > delegate() dg) > { > writeln(&dg); > clickHandlers ~= dg; > } > > It won't crash. But if I comment out the writeln() call it crashes > with an access violation. I've tested this a few dozen times. This > definitely looks like a compiler bug. But I have to reduce it first > before I file it. |
Copyright © 1999-2021 by the D Language Foundation