From e8a5f07843d768829b825033b3e7839493ec374e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 18 Feb 2016 23:52:12 -0800 Subject: 2674 Make it explicit that I don't currently intend to further replace type ingredients inside replacements. That might well make sense, but I've not thought up any use cases or tests for it, and it seems excessive at the moment. And when I find bugs I keep wondering if the repeated replace might be the problem. No longer. --- 058shape_shifting_container.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/058shape_shifting_container.cc b/058shape_shifting_container.cc index 612f0463..7b11a61e 100644 --- a/058shape_shifting_container.cc +++ b/058shape_shifting_container.cc @@ -233,6 +233,7 @@ bool contains_type_ingredient(const type_tree* type) { return contains_type_ingredient(type->left) || contains_type_ingredient(type->right); } +// ugly and likely wrong; maybe avoid replacing in place? void replace_type_ingredients(type_tree* element_type, string_tree* element_type_name, const type_tree* callsite_type, const string_tree* callsite_type_name) { if (!callsite_type) return; // error but it's already been raised above if (!element_type) return; @@ -250,6 +251,7 @@ void replace_type_ingredients(type_tree* element_type, string_tree* element_type type_tree* old_right = element_type->right; element_type->right = replacement->right ? new type_tree(*replacement->right) : NULL; append(element_type->right, old_right); + const string_tree* replacement_name = nth_type_name(callsite_type_name, type_ingredient_index); element_type_name->value = replacement_name->value; assert(!element_type_name->left); // since value is set @@ -257,8 +259,12 @@ void replace_type_ingredients(type_tree* element_type, string_tree* element_type string_tree* old_right_name = element_type_name->right; element_type_name->right = replacement_name->right ? new string_tree(*replacement_name->right) : NULL; append(element_type_name->right, old_right_name); + + replace_type_ingredients(old_right, old_right_name, callsite_type, callsite_type_name); + } + else { + replace_type_ingredients(element_type->right, element_type_name->right, callsite_type, callsite_type_name); } - replace_type_ingredients(element_type->right, element_type_name->right, callsite_type, callsite_type_name); } void append(type_tree*& base, type_tree* extra) { -- cgit 1.4.1-2-gfad0