AQL code:
---------

void main()
{
   let C m = new C;
}

class C
{
    int A = 10;
    int F[i in 0..A] = 10;
}

For field F compile the following expression:
---------------------------------------------

F = function(this : C)
let $I0$ : int .. int = ..(0,A(this));
in
  int[$I0$] =
    let $a : int[int .. int] = new int[..(0,A(this))];
    in {
      let $iterator0 : iterator = #getIterator(..(0,A(this)));
      in
        let i : int = 0;
        in
          while #hasNext($iterator0) do
          {
            i = #next($iterator0);
            $a[i] = 10;
          };
      $a;
    }

generated code:
---------------

CODE ID: #2

        [0]     PUSH_CLOSURE(#2,2,<0,0,1>,<0,0,0>)
        [1]     END
        [2]     PUSH_OFFSET_O(5)
        [3]     GET_FIELD_I([field] A : C -> int)
        [4]     PUSH_I(0)
        [5]     PUSH_INT_RNG
        [6]     PUSH_CLOSURE(#2,9,<0,0,1>,<0,0,1>)
        [7]     LCO_APPLY(0,0,1)
        [8]     END
        [9]     PUSH_OFFSET_O(5)
        [10]    GET_FIELD_I([field] A : C -> int)
        [11]    PUSH_I(0)
        [12]    PUSH_INT_RNG
        [13]    PUSH_MAP_I
        [14]    PUSH_CLOSURE(#2,20,<0,0,1>,<0,0,2>)
        [15]    APPLY(0,0,1)
        [16]    PUSH_OFFSET_O(0)
        [17]    PUSH_I(1)
        [18]    ARRAY_INITIALIZE
        [19]    RETURN_O
        [20]    PUSH_OFFSET_O(5)
        [21]    GET_FIELD_I([field] A : C -> int)
        [22]    PUSH_I(0)
        [23]    PUSH_INT_RNG
        [24]    GET_ITERATOR
        [25]    PUSH_CLOSURE(#2,30,<0,0,1>,<0,0,1>)
        [26]    APPLY(0,0,1)
        [27]    POP_I
        [28]    PUSH_OFFSET_O(0)
        [29]    RETURN_O
        [30]    PUSH_I(0)
        [31]    PUSH_CLOSURE(#2,34,<1,0,0>,<0,0,2>)
        [32]    LCO_APPLY(1,0,0)
        [33]    END
        [34]    PUSH_OFFSET_O(0)
        [35]    ITERATOR_HAS_NEXT
        [36]    JUMP_ON_FALSE(48)
        [37]    PUSH_OFFSET_O(0)
        [38]    ITERATOR_NEXT
        [39]    O_TO_I
        [40]    SET_OFFSET_I(0)
        [41]    POP_I
        [42]    PUSH_OFFSET_I(0)
        [43]    PUSH_OFFSET_O(1)
        [44]    PUSH_I(10)
        [45]    SET_INT_INDEXED_MAP_I
        [46]    POP_I
        [47]    JUMP(34)
        [48]    PUSH_I(-1)
        [49]    RETURN_I


Run time execution trace: this code tries to look for an object at offset 5 which does not exist!
-------------------------------------------------------------------------------------------------

STEP [7] >
===============================================

RESULT STACKS:


        INT:            REAL:           OBJECT:




ENVIRONMENTS:


        INT:            REAL:           OBJECT:


        0:      -1                      0:      C#0{A = 10, F = null}


SAVE STACK:

        2: CODE ID = #5 IP = 2  SP = <0,0,0>    EP = <1,0,0>
        1: CODE ID = #0 IP = 3  SP = <0,0,1>    EP = <1,0,0>
        0: CODE ID = #3 IP = 3  SP = <0,0,0>    EP = <0,0,0>



CALL STACK:




CODE ID: #2

        [0]     PUSH_CLOSURE(#2,2,<0,0,1>,<0,0,0>)
        [1]     END
====>   [2]     PUSH_OFFSET_O(5)
        [3]     GET_FIELD_I([field] A : C -> int)
        [4]     PUSH_I(0)
        [5]     PUSH_INT_RNG
          ...


java.lang.IndexOutOfBoundsException: Index: -5, Size: 1
        at java.util.ArrayList.RangeCheck(ArrayList.java:508)
        at java.util.ArrayList.get(ArrayList.java:320)
        at hlt.language.design.backend.Runtime.getObjectEnv(Runtime.java:717)
        at hlt.language.design.base.PushOffsetObject.execute(PushOffsetObject.j
ava:21)
        at hlt.language.design.backend.Runtime._execute(Runtime.java:985)
        at hlt.language.design.backend.Runtime.run(Runtime.java:975)
        at hlt.language.design.types.ClassInfo.initialize(ClassInfo.java:221)
        at hlt.language.design.types.ClassType.initialize(ClassType.java:331)
        at hlt.language.design.base.PushNewObject.execute(PushNewObject.java:36
)



Subject: Bug when initialisating class fields depending on other fields:

AQL code:
~~~~~~~~
void main()
{
   let C m = new C;
}

class C
{
   int A = 10;
   float F[i in 0..A] = 0.0 + i;
}
~~~~~~~~~~

This gives:

*** Fatal error: (object initialization) failed initializing field [field] F
: C -> real[int .. int]
Detail: java.lang.IndexOutOfBoundsException: Index: -5, Size: 1

On the other hand, when using globals this works:

~~~~~~~~~~~~~~
void main()
{
   let C m = new C;
}

int A = 10;

class C
{
   float F[i in 0..A] = 0.0 + i;
}
~~~~~~~~~~~~~~


