On Friday, 22 April 2016 at 11:16:59 UTC, ag0aep6g wrote:
It's a nested function now. That means, it could reference local variables of main. Make func static and it works.

You can also use a function literal:
----
void main()
{
  immutable int[] array = {
    int[] result = new int[10];
    result[0] = 1;
    return result;
  }();
}

Great! Making it static works. The function literal also works if I add "function int[]()":
void main(string[] args) {
  immutable int[] array = function int[]() {
    int[] result = new int[10];
    result[0] = 1;
    return result;
  }();
}

Reply via email to