[nem-en] closures in constructors

Don Reba don_reba at inbox.ru
Sun Apr 1 04:34:13 CEST 2007


Ran into this bug. In the example below, a function nested inside a constructor attempts to assign a class member, but fails, since it is part of a closure. If this is done inside the constructor itself, and not inside a nested function, everything is fine.


class C
{
	i : int;
	public this()
	{
		def f()
		{
			// assignment of a class member
			// error: assignment to immutable field is allowed only
			// inside code, which is executed inside constructor,
			// but this field access is done through closure
			i = 3;
			// creation of a closure
			mutable j;
			[].Iter(fun (_) { j = 3 });
		}
		f();
	}
}



More information about the devel-en mailing list