From 036566cee9de0a1f2d99e600619e5f8aa4fe3cf0 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 5 May 2016 09:50:20 -0700 Subject: 2925 Thanks Caleb Couch for showing the need for this check. --- 025compare.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to '025compare.cc') diff --git a/025compare.cc b/025compare.cc index 39baa232..c80fcc85 100644 --- a/025compare.cc +++ b/025compare.cc @@ -10,6 +10,13 @@ case EQUAL: { raise << maybe(get(Recipe, r).name) << "'equal' needs at least two ingredients to compare in '" << to_original_string(inst) << "'\n" << end(); break; } + const reagent& exemplar = inst.ingredients.at(0); + for (int i = /*skip exemplar*/1; i < SIZE(inst.ingredients); ++i) { + if (!types_match(inst.ingredients.at(i), exemplar) && !types_match(exemplar, inst.ingredients.at(i))) { + raise << maybe(get(Recipe, r).name) << "'equal' expects ingredients to be all of the same type, but got '" << to_original_string(inst) << "'\n" << end(); + goto finish_checking_instruction; + } + } if (SIZE(inst.products) > 1) { raise << maybe(get(Recipe, r).name) << "'equal' yields exactly one product in '" << to_original_string(inst) << "'\n" << end(); break; @@ -24,7 +31,7 @@ case EQUAL: { case EQUAL: { vector& exemplar = ingredients.at(0); bool result = true; - for (int i = 1; i < SIZE(ingredients); ++i) { + for (int i = /*skip exemplar*/1; i < SIZE(ingredients); ++i) { if (!equal(ingredients.at(i).begin(), ingredients.at(i).end(), exemplar.begin())) { result = false; break; -- cgit 1.4.1-2-gfad0