From d785efe59c4b586763728b2a5574cf5fd8574f17 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 15 Apr 2016 17:40:12 -0700 Subject: 2836 - arcane bug in generic functions Thanks Caleb Couch for finding and reporting this. --- 021check_instruction.cc | 13 +++++++++++++ 058shape_shifting_recipe.cc | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) 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 mapname); 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 -- cgit 1.4.1-2-gfad0