Skip to content

Commit 7c99c30

Browse files
committedJun 19, 2018
fix calling method with comptime pass-by-non-copyign-value self arg
closes #1124
·
0.15.20.3.0
1 parent 42db807 commit 7c99c30

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎src/analyze.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,17 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
14701470
calling_convention_name(fn_type_id.cc)));
14711471
return g->builtin_types.entry_invalid;
14721472
}
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+
14731484
return get_generic_fn_type(g, &fn_type_id);
14741485
} else if (param_is_var_args) {
14751486
if (fn_type_id.cc == CallingConventionC) {

‎test/cases/eval.zig‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,3 +623,17 @@ test "function which returns struct with type field causes implicit comptime" {
623623
const ty = wrap(i32).T;
624624
assert(ty == i32);
625625
}
626+
627+
test "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+
}

0 commit comments

Comments
 (0)
Please sign in to comment.