From 6fff4c53637ed5c9bcdf7d9587a39ccebbe1e610 Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Sat, 12 Mar 2016 04:46:49 -0500 Subject: [PATCH] Fixed up a bug and 2 tests, plus added a better error for when a method isn't found. 69 tests passing! This is everything before ADTs (because of some tests with no success condition, some that depend on the compiler stdlib parts, etc) --- stdlib/ast_transformation.krak | 16 +++++---- tests/test_util.expected_results | 12 +++---- tests/test_vectorTest.expected_results | 46 +++++++++----------------- tests/test_vectorTest.krak | 5 ++- 4 files changed, 34 insertions(+), 45 deletions(-) diff --git a/stdlib/ast_transformation.krak b/stdlib/ast_transformation.krak index 915c52a..e3c980c 100644 --- a/stdlib/ast_transformation.krak +++ b/stdlib/ast_transformation.krak @@ -693,8 +693,10 @@ obj ast_transformation (Object) { if (is_template(enclosing) && is_type_def(enclosing->template.scope[string("~enclosing_scope")][0])) return set(make_this(enclosing->template.scope[string("~enclosing_scope")][0])) } - // we don't close over actual functions - return set<*ast_node>() + // if this is a lambda, we need to close over what it closes over + // we don't need an if - if it's empty and not a lambda, it's empty + // and we don't close over actual functions + return backing.closed_variables } ast_node::return_statement(backing) { println("found an return_statement") @@ -799,12 +801,14 @@ obj ast_transformation (Object) { for (var i = 0; i < parent->template.template_types.size; i++;) inherited_replacements[parent->template.template_types[i]] = parent->template.instantiated_map.reverse_get(get_ast_type(first_param)->type_def)[i].clone() } + var method_name = concat_symbol_tree(node->children[2]) if (template_inst) - second_param = find_or_instantiate_template_function(concat_symbol_tree(node->children[2]), template_inst, get_ast_type(first_param)->type_def, type_vec, template_replacements, inherited_replacements); + second_param = find_or_instantiate_template_function(method_name, template_inst, get_ast_type(first_param)->type_def, type_vec, template_replacements, inherited_replacements); else - second_param = find_or_instantiate_template_function(concat_symbol_tree(node->children[2]), null>(), get_ast_type(first_param)->type_def, type_vec, template_replacements, inherited_replacements); - if (!second_param) - error("Could not find method!") + second_param = find_or_instantiate_template_function(method_name, null>(), get_ast_type(first_param)->type_def, type_vec, template_replacements, inherited_replacements); + if (!second_param) { + error(string("Could not find method ") + method_name + " on the right side of (. or ->) " + concat_symbol_tree(node->children[0]) + ", whole string: " + concat_symbol_tree(node)) + } } } } else { diff --git a/tests/test_util.expected_results b/tests/test_util.expected_results index 731aaa6..76aead1 100644 --- a/tests/test_util.expected_results +++ b/tests/test_util.expected_results @@ -18,20 +18,16 @@ copy construct from 1 to 2 copy construct from 101 to 102 copy construct from 2 to 3 copy construct from 102 to 103 -destruct with 102 destruct with 2 +destruct with 102 +destruct with 101 +destruct with 1 copy construct from 3 to 4 copy construct from 103 to 104 destruct with 3 destruct with 103 -destruct with 101 -destruct with 1 -copy construct from 4 to 5 -copy construct from 104 to 105 +done destruct with 4 destruct with 104 -done -destruct with 5 -destruct with 105 destruct with 100 destruct with 0 diff --git a/tests/test_vectorTest.expected_results b/tests/test_vectorTest.expected_results index 5ff0300..52b6c58 100644 --- a/tests/test_vectorTest.expected_results +++ b/tests/test_vectorTest.expected_results @@ -10,10 +10,8 @@ with references 123456789101112 Constructed: 0 Copied: 0 to 1 -Copied: 1 to 2 -Destroyed: 1 delete vector -Destroyed: 2 +Destroyed: 1 hayyy 4.700000 first @@ -53,41 +51,29 @@ Copied: 100 to 101 Copied: 200 to 201 Copied: 300 to 301 Copied: 101 to 102 -Copied: 102 to 103 -Copied: 103 to 104 -Destroyed: 103 -Destroyed: 102 Copied: 201 to 202 -Copied: 202 to 203 -Copied: 203 to 204 -Destroyed: 203 -Destroyed: 202 Copied: 301 to 302 +Copied: 102 to 103 +Copied: 202 to 203 Copied: 302 to 303 -Copied: 303 to 304 -Destroyed: 303 +Destroyed: 102 +Destroyed: 202 Destroyed: 302 -Copied: 104 to 105 -Copied: 204 to 205 -Copied: 304 to 305 -Destroyed: 104 -Destroyed: 204 -Destroyed: 304 Destroyed: 301 Destroyed: 201 Destroyed: 101 -Copied: 105 to 106 -Copied: 205 to 206 -Copied: 305 to 306 -Destroyed: 105 -Destroyed: 205 -Destroyed: 305 -Destroyed: 206 -Copied: 306 to 307 -Destroyed: 306 +Copied: 103 to 104 +Copied: 203 to 204 +Copied: 303 to 304 +Destroyed: 103 +Destroyed: 203 +Destroyed: 303 +Destroyed: 204 +Copied: 304 to 305 +Destroyed: 304 done -Destroyed: 106 -Destroyed: 307 +Destroyed: 104 +Destroyed: 305 Destroyed: 300 Destroyed: 200 Destroyed: 100 diff --git a/tests/test_vectorTest.krak b/tests/test_vectorTest.krak index 9f825a3..c4dcc72 100644 --- a/tests/test_vectorTest.krak +++ b/tests/test_vectorTest.krak @@ -5,10 +5,13 @@ import vector_literals:* obj AbleToBeDestroyed (Object) { var data:int - fun construct(dat:int):void { + // needed to put it in the vector becuase serilization uses pairs, which defines an empty constructor + fun construct(): *AbleToBeDestroyed return this; + fun construct(dat:int): *AbleToBeDestroyed { data = dat print("Constructed: ") println(data) + return this } fun copy_construct(other:*AbleToBeDestroyed):void { data = other->data+1