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-05-21 22:19:28 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-05-21 22:19:28 -0700
commit5e320aa049bc1d5ad78eec23be0127f4a8d6ec3d (patch)
treed42176acdef4691f62f300cb0df928061077a900 /053recipe_header.cc
parent829fcd8374ea9029119bb37c42aeecf53523995c (diff)
downloadmu-5e320aa049bc1d5ad78eec23be0127f4a8d6ec3d.tar.gz
3876
Thanks Ella Couch for reporting this issue.
Diffstat (limited to '053recipe_header.cc')
-rw-r--r--053recipe_header.cc21
1 files changed, 14 insertions, 7 deletions
diff --git a/053recipe_header.cc b/053recipe_header.cc
index d9495f46..9128f3bb 100644
--- a/053recipe_header.cc
+++ b/053recipe_header.cc
@@ -499,14 +499,15 @@ void fill_in_return_ingredients(const recipe_ordinal r) {
       add_header_products(inst, caller_recipe);
   }
   // fall through return
-  if (caller_recipe.steps.empty()) return;  // error will be raised elsewhere if there's a product in the header; just give up
-  const instruction& final_instruction = caller_recipe.steps.at(SIZE(caller_recipe.steps)-1);
-  if (final_instruction.name != "reply" && final_instruction.name != "return") {
-    instruction inst;
-    inst.name = "return";
-    add_header_products(inst, caller_recipe);
-    caller_recipe.steps.push_back(inst);
+  if (!caller_recipe.steps.empty()) {
+    const instruction& final_instruction = caller_recipe.steps.at(SIZE(caller_recipe.steps)-1);
+    if (final_instruction.name == "reply" || final_instruction.name == "return")
+      return;
   }
+  instruction inst;
+  inst.name = "return";
+  add_header_products(inst, caller_recipe);
+  caller_recipe.steps.push_back(inst);
 }
 
 void add_header_products(instruction& inst, const recipe& caller_recipe) {
@@ -565,6 +566,12 @@ def add2 x:num, y:num -> z:num [
 -transform: instruction: return z:num
 +mem: storing 8 in location 1
 
+:(scenario return_causes_error_in_empty_recipe)
+% Hide_errors = true;
+def foo -> x:num [
+]
++error: foo: tried to read ingredient 'x' in 'return x:num' but it hasn't been written to yet
+
 :(scenario return_after_conditional_return_based_on_header)
 def main [
   1:num/raw <- add2 3, 5