Skip to content

Commit

Permalink
fix calling method with comptime pass-by-non-copyign-value self arg
Browse files Browse the repository at this point in the history
closes #1124
  • Loading branch information
andrewrk committed Jun 19, 2018
1 parent 42db807 commit 7c99c30
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/analyze.cpp
Expand Up @@ -1470,6 +1470,17 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
calling_convention_name(fn_type_id.cc)));
return g->builtin_types.entry_invalid;
}
if (param_node->data.param_decl.type != nullptr) {
TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
if (type_is_invalid(type_entry)) {
return g->builtin_types.entry_invalid;
}
FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index];
param_info->type = type_entry;
param_info->is_noalias = param_node->data.param_decl.is_noalias;
fn_type_id.next_param_index += 1;
}

return get_generic_fn_type(g, &fn_type_id);
} else if (param_is_var_args) {
if (fn_type_id.cc == CallingConventionC) {
Expand Down
14 changes: 14 additions & 0 deletions test/cases/eval.zig
Expand Up @@ -623,3 +623,17 @@ test "function which returns struct with type field causes implicit comptime" {
const ty = wrap(i32).T;
assert(ty == i32);
}

test "call method with comptime pass-by-non-copying-value self parameter" {
const S = struct {
a: u8,

fn b(comptime s: this) u8 {
return s.a;
}
};

const s = S{ .a = 2 };
var b = s.b();
assert(b == 2);
}

0 comments on commit 7c99c30

Please sign in to comment.