fix crash with generic function and implicit cast
parent
83a59c4d07
commit
fcedc35551
|
@ -326,9 +326,9 @@ static void render_node(AstRender *ar, AstNode *node) {
|
|||
AstNode *statement = node->data.block.statements.at(i);
|
||||
print_indent(ar);
|
||||
render_node(ar, statement);
|
||||
fprintf(ar->f, ";\n");
|
||||
}
|
||||
ar->indent -= ar->indent_size;
|
||||
fprintf(ar->f, "\n");
|
||||
print_indent(ar);
|
||||
fprintf(ar->f, "}");
|
||||
break;
|
||||
|
@ -438,7 +438,11 @@ static void render_node(AstRender *ar, AstNode *node) {
|
|||
fprintf(ar->f, ")");
|
||||
break;
|
||||
case NodeTypeArrayAccessExpr:
|
||||
zig_panic("TODO");
|
||||
render_node(ar, node->data.array_access_expr.array_ref_expr);
|
||||
fprintf(ar->f, "[");
|
||||
render_node(ar, node->data.array_access_expr.subscript);
|
||||
fprintf(ar->f, "]");
|
||||
break;
|
||||
case NodeTypeSliceExpr:
|
||||
zig_panic("TODO");
|
||||
case NodeTypeFieldAccessExpr:
|
||||
|
|
|
@ -2927,6 +2927,7 @@ static void clone_subtree_list(ZigList<AstNode *> *dest, ZigList<AstNode *> *src
|
|||
dest->resize(src->length);
|
||||
for (int i = 0; i < src->length; i += 1) {
|
||||
dest->at(i) = ast_clone_subtree(src->at(i), next_node_index);
|
||||
dest->at(i)->parent_field = &dest->at(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2958,11 +2959,12 @@ AstNode *ast_clone_subtree(AstNode *old_node, uint32_t *next_node_index) {
|
|||
memcpy(new_node, old_node, sizeof(AstNode));
|
||||
new_node->create_index = *next_node_index;
|
||||
*next_node_index += 1;
|
||||
new_node->parent_field = nullptr;
|
||||
|
||||
switch (new_node->type) {
|
||||
case NodeTypeRoot:
|
||||
clone_subtree_list(&new_node->data.root.top_level_decls, &old_node->data.root.top_level_decls,
|
||||
next_node_index);
|
||||
clone_subtree_list(&new_node->data.root.top_level_decls,
|
||||
&old_node->data.root.top_level_decls, next_node_index);
|
||||
break;
|
||||
case NodeTypeFnProto:
|
||||
clone_subtree_tld(&new_node->data.fn_proto.top_level_decl, &old_node->data.fn_proto.top_level_decl,
|
||||
|
|
|
@ -1667,7 +1667,7 @@ extern void (*fn_ptr)(void);
|
|||
)SOURCE", 2,
|
||||
"pub extern var fn_ptr: ?extern fn();",
|
||||
R"SOURCE(pub inline fn foo() {
|
||||
(??fn_ptr)()
|
||||
(??fn_ptr)();
|
||||
})SOURCE");
|
||||
|
||||
|
||||
|
|
|
@ -975,3 +975,14 @@ pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 {
|
|||
.data = []f32 { x, y, z, },
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#attribute("test")
|
||||
fn generic_fn_with_implicit_cast() {
|
||||
assert(get_first_byte(u8)([]u8 {13}) == 13);
|
||||
assert(get_first_byte(u16)([]u16 {0, 13}) == 0);
|
||||
}
|
||||
fn get_byte(ptr: ?&u8) -> u8 {*??ptr}
|
||||
fn get_first_byte(T: type)(mem: []T) -> u8 {
|
||||
get_byte((&u8)(&mem[0]))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue