about summary refs log tree commit diff stats
path: root/034address.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-05-06 21:35:46 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-05-06 21:35:46 -0700
commit2c91ac0c6a4b77f268e119eb2366dbc440cbc61f (patch)
tree6f735341683d68077e67c31a32bb82fa9371fbb2 /034address.cc
parenteed2f30ee1a512e632c304b67eb41ec4230e7dea (diff)
downloadmu-2c91ac0c6a4b77f268e119eb2366dbc440cbc61f.tar.gz
3847
Fix a crash on an invalid program. Thanks Lakshman Swaminathan for reporting
this issue.
Diffstat (limited to '034address.cc')
-rw-r--r--034address.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/034address.cc b/034address.cc
index c8a171ec..27f7af87 100644
--- a/034address.cc
+++ b/034address.cc
@@ -277,6 +277,7 @@ void transform_new_to_allocate(const recipe_ordinal r) {
     instruction& inst = get(Recipe, r).steps.at(i);
     // Convert 'new' To 'allocate'
     if (inst.name == "new") {
+      if (inst.ingredients.empty()) return;  // error raised elsewhere
       inst.operation = ALLOCATE;
       type_tree* type = new_type_tree(inst.ingredients.at(0).name);
       inst.ingredients.at(0).set_value(size_of(type));
@@ -425,3 +426,10 @@ def main [
 ]
 +new: routine allocated memory from 1000 to 1003
 +new: routine allocated memory from 1003 to 1006
+
+:(scenario new_without_ingredient)
+% Hide_errors = true;
+def main [
+  1:address:number <- new  # missing ingredient
+]
++error: main: 'new' requires one or two ingredients, but got '1:address:number <- new'