diff --git a/stdlib/ast_transformation.krak b/stdlib/ast_transformation.krak index bbf297d..2e9f069 100644 --- a/stdlib/ast_transformation.krak +++ b/stdlib/ast_transformation.krak @@ -513,7 +513,8 @@ fun get_builtin_function(name: string, param_types: vector<*type>): *ast_node { fun unify_type(template_type: *tree, param_type: *type, new_map: *map, template_replacements: map) { println(string("Unifying type: ") + concat_symbol_tree(template_type)) // first get rid of the reference if we have it - we don't care for unification - template_type = get_node("pre_reffed", template_type) + if (get_node("pre_reffed", template_type)) + template_type = get_node("pre_reffed", template_type) // There are a couple options for the template parameter type here // 1) template type - perfect, stick it in the map, that's what we're here for // 2) basic type - stick it in the map, it won't get copied out so no worries @@ -524,8 +525,13 @@ fun unify_type(template_type: *tree, param_type: *type, new_map: *mapchildren.size == 1) new_map->set(concat_symbol_tree(template_type), param_type) - else + else if (get_node("\"\\*\"", template_type)) + unify_type(template_type->children[1], param_type->clone_with_decreased_indirection(), new_map, template_replacements) + else { + println(template_type->children[0]->data.name) + println(template_type->children[0]->data.data) error("TYPE INFERENCE NOT GOOD ENOUGH") + } } fun find_or_instantiate_function_template(identifier: *tree, template_inst: *tree, scope: *ast_node, param_types: vector<*type>, template_replacements: map): *ast_node { var name = concat_symbol_tree(identifier) @@ -695,6 +701,7 @@ fun concat_symbol_tree(node: *tree): string { node->children.for_each(fun(child: *tree) str += concat_symbol_tree(child);) return str } + fun get_node(lookup: *char, parent: *tree): *tree { return get_node(string(lookup), parent) } diff --git a/tests/to_parse.krak b/tests/to_parse.krak index 36ae936..36b284c 100644 --- a/tests/to_parse.krak +++ b/tests/to_parse.krak @@ -37,8 +37,8 @@ fun return_something_p_1(it: Something): Something { return it } */ -/*fun id(in: *T): *T return in;*/ -fun id(in: T): T return in; +fun id(in: *T): *T return in; +/*fun id(in: T): T return in;*/ fun other_id(in: T): T { var a: T a = in