template classes discriminated in receiving invariant arguments

Denis Koroskin 2korden at gmail.com
Sun Oct 5 17:28:07 PDT 2008


You just discovered a bug:

import std.stdio;

class Foo(T, int n) {
     void bar(T[n] array)
     {
         array[0] = 42;
     }
}

void main() {
     auto foo = new Foo!(int, 3);

     invariant(int[3]) array = [0, 1, 2];
	
     //array[0] = 42; Error: array[0] isn't mutable

     writefln(array); // [0 1 2]
     foo.bar(array);
     writefln(array); // [42 1 2]
}


More information about the Digitalmars-d-learn mailing list