Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 30, 2017 static this not run? | ||||
---|---|---|---|---|
| ||||
I want a module level initialised delegate. if I try module foo; enum Status { success, } class StatusException : Exception { Status s; // usual exception constructors } void delegate(Status) onError = (Status s) { throw new StatusException(s);}; I get a error like cannot initialise something that needs a context at compile time. Ignoring the fact the the initialiser does not need a context, if I do void delegate(Status) onError; static this() { onError = (Status s) { throw new StatusException(s);}; } void main() { import std.stdio; writeln(onError.funcptr); // null } WAT? void delegate(Status) onError; static this() { import core.stdc.stdio; printf("initialising onError"); onError = (Status s) { throw new StatusException(s);}; printf("initialising onError: funcptr = 0x%x", onError.funcptr); } void main() { import std.stdio; writeln(onError.funcptr); } output: null No "initialising onError", the static this is not even being run! I'm using LDC master. See also https://github.com/libmir/dcompute/issues/32 |
September 30, 2017 Re: static this not run? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | On Saturday, 30 September 2017 at 06:15:41 UTC, Nicholas Wilson wrote:
> No "initialising onError", the static this is not even being run!
> I'm using LDC master.
>
> See also https://github.com/libmir/dcompute/issues/32
LDC 1.4, DMD 2.076, DMD ~master and finally GDC all give the expected result here
"initialising onErrorinitialising onError: funcptr = 0x<some address>"
each time using:
---
enum Status {success,}
class StatusException : Exception
{
this(Status s) {this.s = s;super("");}
Status s;
}
void delegate(Status) onError;
static this()
{
import core.stdc.stdio;
printf("initialising onError");
onError = (Status s) { throw new StatusException(s);};
printf("initialising onError: funcptr = 0x%x", onError.funcptr);
}
void main()
{
import std.stdio;
writeln(onError.funcptr);
}
---
|
September 30, 2017 Re: static this not run? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On Saturday, 30 September 2017 at 08:49:14 UTC, user1234 wrote:
> On Saturday, 30 September 2017 at 06:15:41 UTC, Nicholas Wilson wrote:
>> No "initialising onError", the static this is not even being run!
>> I'm using LDC master.
>>
>> See also https://github.com/libmir/dcompute/issues/32
>
> LDC 1.4, DMD 2.076, DMD ~master and finally GDC all give the expected result here
>
> "initialising onErrorinitialising onError: funcptr = 0x<some address>"
>
> each time using:
>
> ---
> enum Status {success,}
>
> class StatusException : Exception
> {
> this(Status s) {this.s = s;super("");}
> Status s;
> }
>
> void delegate(Status) onError;
>
> static this()
> {
> import core.stdc.stdio;
> printf("initialising onError");
> onError = (Status s) { throw new StatusException(s);};
> printf("initialising onError: funcptr = 0x%x", onError.funcptr);
> }
>
> void main()
> {
> import std.stdio;
> writeln(onError.funcptr);
> }
> ---
Hmm. Everything except for the main function was in a different module, I dont see why that would cause it to not be run, but then bugs have a tendency to do strange things like that. I'll have to dust mite DCompute and see what it gets as a minimal case.
|
September 30, 2017 Re: static this not run? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | On Saturday, 30 September 2017 at 12:07:21 UTC, Nicholas Wilson wrote:
> Hmm. Everything except for the main function was in a different module, I dont see why that would cause it to not be run, but then bugs have a tendency to do strange things like that. I'll have to dust mite DCompute and see what it gets as a minimal case.
[The object needs to be pulled in during linking.]
|
Copyright © 1999-2021 by the D Language Foundation