mirror of
https://github.com/ziglang/zig.git
synced 2026-01-30 03:03:46 +00:00
fix calling method with comptime pass-by-non-copyign-value self arg
closes #1124
This commit is contained in:
parent
42db807f37
commit
7c99c30bf4
@ -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) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user