www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Very strange compilation error

reply "Jack Applegame" <japplegame gmail.com> writes:
I don't understand why this code doesn't compile:

http://dpaste.dzfl.pl/dfd8df7f80ad
Oct 15 2014
next sibling parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Wednesday, 15 October 2014 at 19:29:27 UTC, Jack Applegame 
wrote:
 I don't understand why this code doesn't compile:

 http://dpaste.dzfl.pl/dfd8df7f80ad
that should be immutable(ubyte)[] not immutable ubyte[] which is equivalent to immutable(ubyte[]). You can't overwrite immutable data, hence the error.
Oct 15 2014
parent reply Nils =?UTF-8?B?Qm/Dn3VuZw==?= <nilsbossung googlemail.com> writes:
On Wednesday 15 October 2014 22:13, John Colvin wrote:

 On Wednesday, 15 October 2014 at 19:29:27 UTC, Jack Applegame
 wrote:
 I don't understand why this code doesn't compile:

 http://dpaste.dzfl.pl/dfd8df7f80ad
that should be immutable(ubyte)[] not immutable ubyte[] which is equivalent to immutable(ubyte[]). You can't overwrite immutable data, hence the error.
Then Foo1 foo1; foo1 = Foo1(); // compiles shouldn't compile either.
Oct 15 2014
parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Wednesday, 15 October 2014 at 21:28:05 UTC, Nils Boßung wrote:
 On Wednesday 15 October 2014 22:13, John Colvin wrote:

 On Wednesday, 15 October 2014 at 19:29:27 UTC, Jack Applegame
 wrote:
 I don't understand why this code doesn't compile:

 http://dpaste.dzfl.pl/dfd8df7f80ad
that should be immutable(ubyte)[] not immutable ubyte[] which is equivalent to immutable(ubyte[]). You can't overwrite immutable data, hence the error.
Then Foo1 foo1; foo1 = Foo1(); // compiles shouldn't compile either.
Good point. That's an accepts-invalid IMO. Nonetheless: union { string a; immutable ubyte[] b; } is broken, it is effectively casting away immutability. union { string a; immutable(ubyte)[] b; } is the correct approach.
Oct 16 2014
prev sibling parent Nils =?UTF-8?B?Qm/Dn3VuZw==?= <nilsbossung googlemail.com> writes:
On Wednesday 15 October 2014 21:29, Jack Applegame wrote:

 I don't understand why this code doesn't compile:
 
 http://dpaste.dzfl.pl/dfd8df7f80ad
Immutability issues with unions ring a bell for me. This may be related to mentions std.date.SysTime. Here's a reduced version of your test case: --- struct Rebindable { union { int m; immutable int i; } void opAssign(Rebindable another) {} } struct Foo3 { // Remove the union or _timezone and dmd accepts it. union { int m; immutable int i; } Rebindable _timezone; } void main() { Foo3 foo3; foo3 = Foo3(); } --- [1] https://issues.dlang.org/show_bug.cgi?id=12885 [2] https://github.com/D-Programming-Language/dmd/pull/2665
Oct 15 2014