import std.stdio;
class C
{
auto foo()
{
auto self = this;
struct S
{
auto foobar()
{
return self.bar();
}
}
return S.init; // lead to crash, S() works OK
}
int bar()
{
return 666;
}
}
void main()
{
auto c = new C;
c.foo().foobar.writeln;
}
Comment #1 by dfj1esp02 — 2021-12-20T15:40:46Z
You mean you want it for the sake of consistency? FWIW init is now static data that always exists to initialize a variable, but a nested struct needs a dynamic initializer to set the context pointer, init can't do it, but a constructor does it.
Comment #2 by razvan.nitu1305 — 2022-12-09T11:59:10Z
Yes, anonymous4 is right. .init is represented by statically known data. The context pointer has the init value of every other pointer, "null". So in this case, this is a programming mistake.