generic functions use correct type for generic args

See #22
This commit is contained in:
Andrew Kelley 2016-04-07 11:34:04 -07:00
parent 1d4c66b56b
commit ee22e87296
2 changed files with 7 additions and 2 deletions

View File

@ -4667,8 +4667,8 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp
AstNode **generic_param_type_node = &generic_param_decl_node->data.param_decl.type;
TypeTableEntry *expected_param_type = analyze_expression(g, decl_node->owner,
decl_node->owner->block_context, nullptr, *generic_param_type_node);
TypeTableEntry *expected_param_type = analyze_type_expr(g, decl_node->owner,
decl_node->owner->block_context, *generic_param_type_node);
if (expected_param_type->id == TypeTableEntryIdInvalid) {
return expected_param_type;
}

View File

@ -516,12 +516,17 @@ three)";
fn simple_generic_fn() {
assert(max(i32)(3, -1) == 3);
assert(max(f32)(0.123, 0.456) == 0.456);
assert(add(2)(3) == 5);
}
fn max(T: type)(a: T, b: T) -> T {
return if (a > b) a else b;
}
fn add(a: i32)(b: i32) -> i32 {
return a + b;
}
#attribute("test")
fn constant_equal_function_pointers() {