diff --git a/stdlib/ast_transformation.krak b/stdlib/ast_transformation.krak index 2169bfb..1767601 100644 --- a/stdlib/ast_transformation.krak +++ b/stdlib/ast_transformation.krak @@ -957,9 +957,28 @@ fun unify_type(template_type: *tree, param_type: *type, new_map: *mapto_string()) new_map->set(concat_symbol_tree(template_type), param_type) } - } else if (get_node("\"\\*\"", template_type)) + } else if (get_node("\"\\*\"", template_type)) { unify_type(template_type->children[1], param_type->clone_with_decreased_indirection(), new_map, template_replacements) - else { + } else if (get_node("template_inst", template_type)) { + if (param_type->is_object()) { + var enclosing_template = param_type->type_def->type_def.scope[string("~enclosing_scope")][0] + if (is_template(enclosing_template)) { + var inst_params = enclosing_template->template.instantiated_map.reverse_get(param_type->type_def) + var template_params = get_nodes("type", get_node("template_inst", template_type)) + if (inst_params.size == template_params.size) { + println("TEMPLATE inference should be successful") + for (var i = 0; i < inst_params.size; i++;) + unify_type(template_params[i], inst_params[i].clone(), new_map, template_replacements) + } else { + println("TEMPLATE inference hit different sizes") + } + } else { + error("TEMPLATE inference hit non parent template") + } + } else { + error("TEMPLATE inference hit non object") + } + } else { println(template_type->children[0]->data.name) println(template_type->children[0]->data.data) error("TYPE INFERENCE NOT GOOD ENOUGH") diff --git a/tests/test_templatedObjectTemplatedFunctionInference.expected_results b/tests/test_templatedObjectTemplatedFunctionInference.expected_results new file mode 100644 index 0000000..bb101b6 --- /dev/null +++ b/tests/test_templatedObjectTemplatedFunctionInference.expected_results @@ -0,0 +1,2 @@ +true +true diff --git a/tests/test_templatedObjectTemplatedFunctionInference.krak b/tests/test_templatedObjectTemplatedFunctionInference.krak new file mode 100644 index 0000000..b8f7c69 --- /dev/null +++ b/tests/test_templatedObjectTemplatedFunctionInference.krak @@ -0,0 +1,19 @@ +import simple_print:* + +obj Object { + var data: T +} + +fun get(a: Object): T { + var temp = a.data; + println(temp) + return temp +} + +fun main(): int { + var b: Object + b.data = true + println(get(b)) + return 0 +} +