authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-19 19:35:35-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-19 19:35:59-04:00
log7c99c30bf406342a45833963ce630bb104aef00e
tree8fe57fa4a447cfddd4e65d32763072ed69661f18
parent42db807f375d0c8fe248eebcb4eaeed71b43075d

fix calling method with comptime pass-by-non-copyign-value self arg

closes #1124

2 files changed, 25 insertions(+), 0 deletions(-)

src/analyze.cpp+11
...@@ -1470,6 +1470,17 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c...@@ -1470,6 +1470,17 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1470 calling_convention_name(fn_type_id.cc)));1470 calling_convention_name(fn_type_id.cc)));
1471 return g->builtin_types.entry_invalid;1471 return g->builtin_types.entry_invalid;
1472 }1472 }
1473 if (param_node->data.param_decl.type != nullptr) {
1474 TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
1475 if (type_is_invalid(type_entry)) {
1476 return g->builtin_types.entry_invalid;
1477 }
1478 FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index];
1479 param_info->type = type_entry;
1480 param_info->is_noalias = param_node->data.param_decl.is_noalias;
1481 fn_type_id.next_param_index += 1;
1482 }
1483
1473 return get_generic_fn_type(g, &fn_type_id);1484 return get_generic_fn_type(g, &fn_type_id);
1474 } else if (param_is_var_args) {1485 } else if (param_is_var_args) {
1475 if (fn_type_id.cc == CallingConventionC) {1486 if (fn_type_id.cc == CallingConventionC) {
test/cases/eval.zig+14
...@@ -623,3 +623,17 @@ test "function which returns struct with type field causes implicit comptime" {...@@ -623,3 +623,17 @@ test "function which returns struct with type field causes implicit comptime" {
623 const ty = wrap(i32).T;623 const ty = wrap(i32).T;
624 assert(ty == i32);624 assert(ty == i32);
625}625}
626
627test "call method with comptime pass-by-non-copying-value self parameter" {
628 const S = struct {
629 a: u8,
630
631 fn b(comptime s: this) u8 {
632 return s.a;
633 }
634 };
635
636 const s = S{ .a = 2 };
637 var b = s.b();
638 assert(b == 2);
639}