Bug 10496 – Initialization in lazy function parameter allows immutable member not to be initialized

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-28T09:00:44Z
Last change time
2024-12-13T18:08:47Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
David Eckardt
Moved to GitHub: dmd#18619 →

Comments

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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18619 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB