diff options
Diffstat (limited to '059shape_shifting_recipe.cc')
-rw-r--r-- | 059shape_shifting_recipe.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/059shape_shifting_recipe.cc b/059shape_shifting_recipe.cc index e308be3a..7ee400cb 100644 --- a/059shape_shifting_recipe.cc +++ b/059shape_shifting_recipe.cc @@ -193,6 +193,11 @@ void save_or_deduce_type_name(reagent& x, map<string, string_tree*>& type_name) } void compute_type_ingredient_mappings(const recipe& exemplar, const instruction& inst, map<string, const string_tree*>& mappings, const recipe& caller_recipe, bool* error) { + if (SIZE(exemplar.ingredients) > SIZE(inst.ingredients)) { + raise << maybe(caller_recipe.name) << "too few ingredients in call '" << inst.to_string() << "'\n" << end(); + *error = true; + return; + } for (long long int i = 0; i < SIZE(exemplar.ingredients); ++i) { const reagent& exemplar_reagent = exemplar.ingredients.at(i); reagent ingredient = inst.ingredients.at(i); @@ -200,6 +205,11 @@ void compute_type_ingredient_mappings(const recipe& exemplar, const instruction& canonize_type(ingredient); accumulate_type_ingredients(exemplar_reagent, ingredient, mappings, exemplar, inst, caller_recipe, error); } + if (SIZE(exemplar.products) > SIZE(inst.products)) { + raise << maybe(caller_recipe.name) << "too few products in call '" << inst.to_string() << "'\n" << end(); + *error = true; + return; + } for (long long int i = 0; i < SIZE(exemplar.products); ++i) { const reagent& exemplar_reagent = exemplar.products.at(i); reagent product = inst.products.at(i); @@ -217,6 +227,7 @@ void accumulate_type_ingredients(const reagent& exemplar_reagent, reagent& refin void accumulate_type_ingredients(const string_tree* exemplar_type, const string_tree* refinement_type, map<string, const string_tree*>& mappings, const recipe& exemplar, const reagent& exemplar_reagent, const instruction& call_instruction, const recipe& caller_recipe, bool* error) { if (!exemplar_type) return; if (!refinement_type) { + // todo: make this smarter; only warn if exemplar_type contains some *new* type ingredient raise_error << maybe(exemplar.name) << "missing type ingredient in " << exemplar_reagent.original_string << '\n' << end(); return; } |