about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-04-15 17:40:12 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-04-15 17:40:12 -0700
commitd785efe59c4b586763728b2a5574cf5fd8574f17 (patch)
tree633f94147f45c544a96828b41005dea791a0e48f
parentd31d70b60e6f136ad99274051ccbd494c4e6d058 (diff)
downloadmu-d785efe59c4b586763728b2a5574cf5fd8574f17.tar.gz
2836 - arcane bug in generic functions
Thanks Caleb Couch for finding and reporting this.
-rw-r--r--021check_instruction.cc13
-rw-r--r--058shape_shifting_recipe.cc24
2 files changed, 37 insertions, 0 deletions
diff --git a/021check_instruction.cc b/021check_instruction.cc
index 898b3214..138aa733 100644
--- a/021check_instruction.cc
+++ b/021check_instruction.cc
@@ -157,10 +157,23 @@ bool types_strictly_match(reagent to, reagent from) {
 bool types_strictly_match(type_tree* to, type_tree* from) {
   if (!to) return true;
   if (!from) return to->value == 0;
+  if (from->value == -1) return from->name == to->name;
   if (to->value != from->value) return false;
   return types_strictly_match(to->left, from->left) && types_strictly_match(to->right, from->right);
 }
 
+void test_unknown_type_does_not_match_unknown_type() {
+  reagent a("a:foo");
+  reagent b("b:bar");
+  CHECK(!types_strictly_match(a, b));
+}
+
+void test_unknown_type_matches_itself() {
+  reagent a("a:foo");
+  reagent b("b:foo");
+  CHECK(types_strictly_match(a, b));
+}
+
 bool is_unsafe(const reagent& r) {
   return has_property(r, "unsafe");
 }
diff --git a/058shape_shifting_recipe.cc b/058shape_shifting_recipe.cc
index c892774d..0c48d596 100644
--- a/058shape_shifting_recipe.cc
+++ b/058shape_shifting_recipe.cc
@@ -401,6 +401,10 @@ void replace_type_ingredients(type_tree* type, const map<string, const type_tree
 
   const type_tree* replacement = get(mappings, type->name);
   trace(9993, "transform") << type->name << " => " << names_to_string(replacement) << end();
+  if (!contains_key(Type_ordinal, replacement->name)) {
+    // error in program; should be reported elsewhere
+    return;
+  }
 
   // type is a single type ingredient
   assert(!type->left);
@@ -984,3 +988,23 @@ def foo x:address:shared:_elem -> y:number [
 ]
 # prefer the concrete variant, ignore concrete types in scoring the shape-shifting variant
 +mem: storing 34 in location 1
+
+:(scenario missing_type_during_specialization)
+% Hide_errors = true;
+# define a shape-shifting recipe
+def foo4 a:_elem [
+]
+# define a container with field 'z'
+container foo2 [
+  z:number
+]
+def main [
+  local-scope
+  x:foo2 <- merge 34
+  y:number <- get x, z:offse  # typo in 'offset'
+  # define a variable with the same name 'z'
+  z:number <- copy 34
+  # trigger specialization of the shape-shifting recipe
+  foo4 z
+]
+# shouldn't crash