about summary refs log tree commit diff stats
path: root/053recipe_header.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-03-02 22:41:18 -0800
committerKartik K. Agaram <vc@akkartik.com>2017-03-02 22:41:18 -0800
commitb5f2a629c2617fc08a3b6d3fcc7d40f3974c8217 (patch)
treee803040bcbd8a08275bebe2d33ce89758ae1c142 /053recipe_header.cc
parente520e7989c207da66130b951d6268d11911b4fcc (diff)
downloadmu-b5f2a629c2617fc08a3b6d3fcc7d40f3974c8217.tar.gz
3752 - fix a couple of segfaults
Thanks Ella Couch for running into these.
Diffstat (limited to '053recipe_header.cc')
-rw-r--r--053recipe_header.cc24
1 files changed, 21 insertions, 3 deletions
diff --git a/053recipe_header.cc b/053recipe_header.cc
index c8904ba3..1f70d934 100644
--- a/053recipe_header.cc
+++ b/053recipe_header.cc
@@ -365,12 +365,29 @@ def foo -> x:num [
 
 :(scenario recipe_headers_check_for_duplicate_names)
 % Hide_errors = true;
-def add2 x:num, x:num -> z:num [
+def foo x:num, x:num -> z:num [
   local-scope
   load-ingredients
   return z
 ]
-+error: add2: 'x' can't repeat in the ingredients
++error: foo: 'x' can't repeat in the ingredients
+
+:(scenario recipe_headers_check_for_duplicate_names_2)
+% Hide_errors = true;
+def foo x:num, x:num [  # no result
+  local-scope
+  load-ingredients
+]
++error: foo: 'x' can't repeat in the ingredients
+
+:(scenario recipe_headers_check_for_missing_types)
+% Hide_errors = true;
+def main [
+  foo 0
+]
+def foo a [  # no type for 'a'
+]
++error: foo: ingredient 'a' has no type
 
 :(before "End recipe Fields")
 map<string, int> ingredient_index;
@@ -381,10 +398,11 @@ Transform.push_back(check_header_ingredients);  // idempotent
 :(code)
 void check_header_ingredients(const recipe_ordinal r) {
   recipe& caller_recipe = get(Recipe, r);
-  if (caller_recipe.products.empty()) return;
   caller_recipe.ingredient_index.clear();
   trace(9991, "transform") << "--- checking return instructions against header for " << caller_recipe.name << end();
   for (int i = 0;  i < SIZE(caller_recipe.ingredients);  ++i) {
+    if (caller_recipe.ingredients.at(i).type == NULL)
+      raise << maybe(caller_recipe.name) << "ingredient '" << caller_recipe.ingredients.at(i).name << "' has no type\n" << end();
     if (contains_key(caller_recipe.ingredient_index, caller_recipe.ingredients.at(i).name))
       raise << maybe(caller_recipe.name) << "'" << caller_recipe.ingredients.at(i).name << "' can't repeat in the ingredients\n" << end();
     put(caller_recipe.ingredient_index, caller_recipe.ingredients.at(i).name, i);