Re: Qualified destructors / immutable objects

2015-06-14 Thread via Digitalmars-d-learn
On Sunday, 14 June 2015 at 07:28:39 UTC, anonymous wrote: To come back to destructors and immutable objects: Even without the default initialized variables issue it is possible to modify immutable data: struct S { int[] bar; ~this() { bar[0] = 123; } } void foo(immutable(int[]) i)

Re: Qualified destructors / immutable objects

2015-06-14 Thread anonymous via Digitalmars-d-learn
To come back to destructors and immutable objects: Even without the default initialized variables issue it is possible to modify immutable data: struct S { int[] bar; ~this() { bar[0] = 123; } } void foo(immutable(int[]) i) { immutable(S) s = immutable S(i); } void main() { im

Re: Qualified destructors / immutable objects

2015-06-13 Thread anonymous via Digitalmars-d-learn
Is there an existing issue on issue.dlang.org? If not can you report it https://issues.dlang.org/show_bug.cgi?id=10376

Re: Qualified destructors / immutable objects

2015-06-13 Thread Daniel Kozak via Digitalmars-d-learn
On Friday, 12 June 2015 at 15:36:22 UTC, anonymous wrote: no need for ~this() to modify immutable data: class C { int a; this(int a) { this.a = a; } } struct S { C elem = new C(42); } void main() { import std.stdio; immutable(S) s1;

Re: Qualified destructors / immutable objects

2015-06-12 Thread via Digitalmars-d-learn
On Friday, 12 June 2015 at 15:36:22 UTC, anonymous wrote: no need for ~this() to modify immutable data: I think that's a another bug related to init values.

Re: Qualified destructors / immutable objects

2015-06-12 Thread anonymous via Digitalmars-d-learn
no need for ~this() to modify immutable data: class C { int a; this(int a) { this.a = a; } } struct S { C elem = new C(42); } void main() { import std.stdio; immutable(S) s1; // Error: cannot modify immutable expression s1.e

Re: Qualified destructors / immutable objects

2015-06-12 Thread anonymous via Digitalmars-d-learn
I cannot find a way to actually modify immutable memory with it... a.d: class C { int a; this(int a) { this.a = a; } } struct S { int x; C elem = new C(42); ~this() { import std.stdio; writeln("mutable ~this()"); x = 1; elem.a = 123;

Qualified destructors / immutable objects

2015-06-12 Thread via Digitalmars-d-learn
struct S { int x; ~this() { import std.stdio; writeln("mutable ~this()"); x = 1; } } void main() { const(S) s1; immutable(S) s2; } Prints: mutable ~this() mutable ~this() This looks very wrong,