Cannot call mutable method on final struct

Christopher Wright dhasenan at
Mon Sep 10 04:57:06 PDT 2007

Carlos Santander wrote:
> I don't use D 2.0, but here it goes...
> string is const(char)[] or const char[] or something like that... It's 
> const, anyway, so you aren't supposed to modify it. Replace "string 
> value" with "char[] value".

If I use char[] rather than string, it fails with the error message I 
stated (and indeed, in the original, I used char[] accidentally). If I 
just call Box.toString and don't do anything with the returned string, 
it fails with the same error message.

'string ~= whatever' is valid because the string is not final. The 
compiler rewrites it as 'string = string ~ whatever'.

New minimal test case:
import std.boxer;
void main () {
    foreach (b; boxArray(9, 'b')) {

More information about the Digitalmars-d-learn mailing list