about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--030container.cc14
-rw-r--r--032array.cc14
-rw-r--r--035lookup.cc2
3 files changed, 29 insertions, 1 deletions
diff --git a/030container.cc b/030container.cc
index 6bf8bbdc..8c570498 100644
--- a/030container.cc
+++ b/030container.cc
@@ -435,6 +435,10 @@ case PUT: {
     raise << maybe(get(Recipe, r).name) << "'put " << base.original_string << ", " << offset.original_string << "' should write to " << names_to_string_without_quotes(element.type) << " but '" << value.name << "' has type " << names_to_string_without_quotes(value.type) << '\n' << end();
     break;
   }
+  if (!inst.products.empty() && inst.products.at(0).name != inst.ingredients.at(0).name) {
+    raise << maybe(get(Recipe, r).name) << "product of 'put' must be first ingredient '" << inst.ingredients.at(0).original_string << "', but got '" << inst.products.at(0).original_string << "'\n" << end();
+    break;
+  }
   break;
 }
 :(before "End Primitive Recipe Implementations")
@@ -461,6 +465,16 @@ case PUT: {
   goto finish_instruction;
 }
 
+:(scenario put_product_error)
+% Hide_errors = true;
+def main [
+  local-scope
+  load-ingredients
+  1:point <- merge 34, 35
+  3:point <- put 1:point, x:offset, 36
+]
++error: main: product of 'put' must be first ingredient '1:point', but got '3:point'
+
 //:: Allow containers to be defined in mu code.
 
 :(scenarios load)
diff --git a/032array.cc b/032array.cc
index 016e9d19..8d08fdc2 100644
--- a/032array.cc
+++ b/032array.cc
@@ -355,6 +355,10 @@ case PUT_INDEX: {
     raise << maybe(get(Recipe, r).name) << "'put-index " << base.original_string << ", " << inst.ingredients.at(1).original_string << "' should store " << names_to_string_without_quotes(element.type) << " but '" << value.name << "' has type " << names_to_string_without_quotes(value.type) << '\n' << end();
     break;
   }
+  if (!inst.products.empty() && inst.products.at(0).name != inst.ingredients.at(0).name) {
+    raise << maybe(get(Recipe, r).name) << "product of 'put-index' must be first ingredient '" << inst.ingredients.at(0).original_string << "', but got '" << inst.products.at(0).original_string << "'\n" << end();
+    break;
+  }
   break;
 }
 :(before "End Primitive Recipe Implementations")
@@ -419,6 +423,16 @@ def main [
 ]
 +error: main: invalid index -1
 
+:(scenario put_index_product_error)
+% Hide_errors = true;
+def main [
+  local-scope
+  load-ingredients
+  1:array:number:3 <- create-array
+  4:array:number:3 <- put-index 1:array:number:3, 0, 34
+]
++error: main: product of 'put-index' must be first ingredient '1:array:number:3', but got '4:array:number:3'
+
 //:: compute the length of an array
 
 :(scenario array_length)
diff --git a/035lookup.cc b/035lookup.cc
index 382d72aa..e56078bc 100644
--- a/035lookup.cc
+++ b/035lookup.cc
@@ -315,7 +315,7 @@ def main [
   5:address:number <- copy 10/unsafe
   # 10 reserved for refcount
   11:number <- copy 1
-  5:address:array:number/lookup <- put-index 1:array:number:3, 5:address:number/lookup, 34
+  1:array:number:3 <- put-index 1:array:number:3, 5:address:number/lookup, 34
 ]
 +mem: storing 34 in location 3