New test that tests template inference through instantiated templates, implemented it in kalypso, 51 tests passing

This commit is contained in:
Nathan Braswell
2016-03-08 12:09:27 -05:00
parent 9eb5db84ab
commit 5b3af2fa25
3 changed files with 42 additions and 2 deletions

View File

@@ -957,9 +957,28 @@ fun unify_type(template_type: *tree<symbol>, param_type: *type, new_map: *map<st
println(string("setting ") + concat_symbol_tree(template_type) + " equal to " + param_type->to_string()) println(string("setting ") + concat_symbol_tree(template_type) + " equal to " + param_type->to_string())
new_map->set(concat_symbol_tree(template_type), param_type) 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) 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.name)
println(template_type->children[0]->data.data) println(template_type->children[0]->data.data)
error("TYPE INFERENCE NOT GOOD ENOUGH") error("TYPE INFERENCE NOT GOOD ENOUGH")

View File

@@ -0,0 +1,2 @@
true
true

View File

@@ -0,0 +1,19 @@
import simple_print:*
obj Object<T> {
var data: T
}
fun get<T>(a: Object<T>): T {
var temp = a.data;
println(temp)
return temp
}
fun main(): int {
var b: Object<bool>
b.data = true
println(get(b))
return 0
}