Fixed type checking for multidimensional arrays. default tip
authorAsher Baker <asherkin@gmail.com>
Mon Jun 10 15:52:44 2013 +0100 (2013-06-10)
changeset 2653a903b89a514
parent 264 70b8f318c379
Fixed type checking for multidimensional arrays.
src/compiler/NameBinding.cpp
tests/basic/multidim.out
tests/basic/multidim.sp
     1.1 --- a/src/compiler/NameBinding.cpp	Mon Jun 10 01:50:18 2013 +0100
     1.2 +++ b/src/compiler/NameBinding.cpp	Mon Jun 10 15:52:44 2013 +0100
     1.3 @@ -655,12 +655,12 @@
     1.4      ArrayType *buildArrayType(Handle<Type> contained, TypeQualifiers quals, int dims[MAX_ARRAY_DEPTH], size_t postlevels) {
     1.5          Local<Type> type(zone_, contained);
     1.6  
     1.7 -        for (size_t i = postlevels - 1; i < postlevels; i--) {
     1.8 -            int size = dims[i] > 0
     1.9 -                       ? dims[i]
    1.10 +        for (size_t i = postlevels; i > 0; --i) {
    1.11 +            int size = dims[i - 1] > 0
    1.12 +                       ? dims[i - 1]
    1.13                         : ArrayType::DYNAMIC_ARRAY_SIZE;
    1.14              
    1.15 -            if ((type = zone_->types()->newArray(contained, size)) == NULL)
    1.16 +            if ((type = zone_->types()->newArray(type, size)) == NULL)
    1.17                  return NULL;
    1.18              if ((type = zone_->types()->qualify(type, quals)) == NULL)
    1.19                  return NULL;
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tests/basic/multidim.out	Mon Jun 10 15:52:44 2013 +0100
     2.3 @@ -0,0 +1,1 @@
     2.4 +45
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tests/basic/multidim.sp	Mon Jun 10 15:52:44 2013 +0100
     3.3 @@ -0,0 +1,12 @@
     3.4 +native PrintNum(num);
     3.5 +
     3.6 +public main()
     3.7 +{
     3.8 +	new cake[1][3];
     3.9 +	cake[0][0] = 5;
    3.10 +	cake[0][1] = 45;
    3.11 +	cake[0][2] = -2;
    3.12 +
    3.13 +	PrintNum(cake[0][1]);
    3.14 +}
    3.15 +