Comment #0 by david.eckardt — 2013-06-28T09:00:44Z
class C
{
immutable int x;
this()
{
this.f(this.x = 5);
}
void f(lazy int x){}
}
C.int isn't initialized, although this code compiles.
Whether C.int is initialized or not depends on the, in general indeterministic, behavior of f(), this should be a compile time error.
Comment #1 by public — 2013-06-28T09:21:47Z
I think this is part of a bigger problem:
----------------------------------------
class A
{
immutable int x;
void delegate() f;
this()
{
x = 40;
f = () { x = 42; };
}
}
void main()
{
import std.stdio;
auto a = new A();
writeln(a.x);
a.f();
writeln(a.x);
}
----------------------------------------
40
42
Comment #2 by maxim — 2013-06-28T11:08:00Z
The root is that delegate construction does not respect immutability at all.
struct S
{
void foo() immutable {}
void baz()
{
//foo();
(&foo)();
}
}
Comment #3 by robert.schadek — 2024-12-13T18:08:47Z