about summary refs log tree commit diff stats
path: root/011load.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-07-25 00:20:35 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-07-25 00:23:15 -0700
commitc5e965d87fe2ef50ac70722eea73e89095b9178d (patch)
tree9be8da3096747e6bd2542e5d44e97c12caf254b7 /011load.cc
parent35064671ef90ec6e35eafd9b15363058bf4f23f4 (diff)
downloadmu-c5e965d87fe2ef50ac70722eea73e89095b9178d.tar.gz
1845 - never ever redefine the scenario's recipe
A couple of times now I've accidentally named a scenario the same thing
as a recipe inside it that I define using 'run' or something. The
resulting infinite loop is invariably non-trivial to debug.
Diffstat (limited to '011load.cc')
-rw-r--r--011load.cc13
1 files changed, 8 insertions, 5 deletions
diff --git a/011load.cc b/011load.cc
index 9142429c..7135b548 100644
--- a/011load.cc
+++ b/011load.cc
@@ -33,7 +33,10 @@ vector<recipe_ordinal> load(istream& in) {
       if (Recipe_ordinal.find(recipe_name) == Recipe_ordinal.end()) {
         Recipe_ordinal[recipe_name] = Next_recipe_ordinal++;
       }
-      // Warn On Redefinition
+      if (warn_on_redefine(recipe_name)
+          && Recipe.find(Recipe_ordinal[recipe_name]) != Recipe.end()) {
+        raise << "redefining recipe " << Recipe[Recipe_ordinal[recipe_name]].name << "\n" << end();
+      }
       // todo: save user-defined recipes to mu's memory
       Recipe[Recipe_ordinal[recipe_name]] = slurp_recipe(in);
 //?       cerr << Recipe_ordinal[recipe_name] << ": " << recipe_name << '\n'; //? 1
@@ -204,10 +207,10 @@ void skip_comma(istream& in) {
 bool Hide_redefine_warnings = false;
 :(before "End Setup")
 Hide_redefine_warnings = false;
-:(after "Warn On Redefinition")
-if (!Hide_redefine_warnings
-    && Recipe.find(Recipe_ordinal[recipe_name]) != Recipe.end()) {
-  raise << "redefining recipe " << Recipe[Recipe_ordinal[recipe_name]].name << "\n" << end();
+:(code)
+bool warn_on_redefine(const string& recipe_name) {
+  if (Hide_redefine_warnings) return false;
+  return true;
 }
 
 // for debugging