about summary refs log tree commit diff stats
path: root/025compare.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-05-05 09:50:20 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-05-05 09:50:23 -0700
commit036566cee9de0a1f2d99e600619e5f8aa4fe3cf0 (patch)
tree85062e464fe1781968a91c2482a2f681bc79be7a /025compare.cc
parentc2f7df5fe5b1167200ed53b661f2fbe4b1470ad4 (diff)
downloadmu-036566cee9de0a1f2d99e600619e5f8aa4fe3cf0.tar.gz
2925
Thanks Caleb Couch for showing the need for this check.
Diffstat (limited to '025compare.cc')
-rw-r--r--025compare.cc9
1 files changed, 8 insertions, 1 deletions
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<double>& 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;