fix segfault in generic functions

See #22
This commit is contained in:
Andrew Kelley 2016-04-07 15:09:55 -07:00
parent 3b535d2c3a
commit 28ad4e6d83
2 changed files with 18 additions and 2 deletions

View File

@ -2861,8 +2861,12 @@ static void clone_subtree_list_ptr(ZigList<AstNode *> **dest_ptr, ZigList<AstNod
}
static void clone_subtree_field(AstNode **dest, AstNode *src, uint32_t *next_node_index) {
if (src) {
*dest = ast_clone_subtree(src, next_node_index);
(*dest)->parent_field = dest;
} else {
*dest = nullptr;
}
}
static void clone_subtree_tld(TopLevelDecl *dest, TopLevelDecl *src, uint32_t *next_node_index) {

View File

@ -542,6 +542,18 @@ fn generic_function_equality() {
}
#attribute("test")
fn generic_malloc_free() {
const a = %%mem_alloc(u8)(10);
mem_free(u8)(a);
}
const some_mem : [100]u8 = undefined;
fn mem_alloc(T: type)(n: isize) -> %[]T {
return (&T)(&some_mem[0])[0...n];
}
fn mem_free(T: type)(mem: []T) { }
fn assert(b: bool) {
if (!b) unreachable{}
}