about summary refs log tree commit diff stats
path: root/032array.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-05-04 13:57:32 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-05-04 13:57:32 -0700
commit91ec4681cf42d608221ef3fdbc371fb0836f5303 (patch)
treed139ed961f0792b1cd3ae8bdc9546e5670987f31 /032array.cc
parent6e793202e3dd9a89b88ab291cebbcb788337c592 (diff)
downloadmu-91ec4681cf42d608221ef3fdbc371fb0836f5303.tar.gz
2899
Diffstat (limited to '032array.cc')
-rw-r--r--032array.cc14
1 files changed, 13 insertions, 1 deletions
diff --git a/032array.cc b/032array.cc
index 3d93e84d..485f403f 100644
--- a/032array.cc
+++ b/032array.cc
@@ -239,7 +239,9 @@ type_tree* copy_array_element(const type_tree* type) {
 }
 
 int array_length(const reagent& x) {
-  if (x.type->right->right) {
+  if (x.type->right->right && !x.type->right->right->right  // exactly 3 types
+      && is_integer(x.type->right->right->name)) {  // third 'type' is a number
+    // get size from type
     return to_integer(x.type->right->right->name);
   }
   // this should never happen at transform time
@@ -247,6 +249,16 @@ int array_length(const reagent& x) {
   return get_or_insert(Memory, x.value);
 }
 
+void test_array_length_compound() {
+  put(Memory, 1, 3);
+  put(Memory, 2, 14);
+  put(Memory, 3, 15);
+  put(Memory, 4, 16);
+  reagent x("1:array:address:number");  // 3 types, but not a static array
+  populate_value(x);
+  CHECK_EQ(array_length(x), 3);
+}
+
 :(scenario index_out_of_bounds)
 % Hide_errors = true;
 def main [