mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 16:24:51 +00:00
fix ability to call method on variable at compile time
This commit is contained in:
parent
2b88441295
commit
8b1c6d8b76
12
src/ir.cpp
12
src/ir.cpp
@ -7808,9 +7808,15 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
|
||||
|
||||
size_t next_proto_i = 0;
|
||||
if (first_arg_ptr) {
|
||||
IrInstruction *first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
|
||||
if (first_arg->value.type->id == TypeTableEntryIdInvalid)
|
||||
return ira->codegen->builtin_types.entry_invalid;
|
||||
IrInstruction *first_arg;
|
||||
assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
|
||||
if (handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
|
||||
first_arg = first_arg_ptr;
|
||||
} else {
|
||||
first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
|
||||
if (first_arg->value.type->id == TypeTableEntryIdInvalid)
|
||||
return ira->codegen->builtin_types.entry_invalid;
|
||||
}
|
||||
|
||||
if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, first_arg, &exec_scope, &next_proto_i))
|
||||
return ira->codegen->builtin_types.entry_invalid;
|
||||
|
||||
@ -27,6 +27,10 @@ fn initStaticArrayToUndefined() {
|
||||
|
||||
const Foo = struct {
|
||||
x: i32,
|
||||
|
||||
fn setFooXMethod(foo: &Foo) {
|
||||
foo.x = 3;
|
||||
}
|
||||
};
|
||||
|
||||
fn setFooX(foo: &Foo) {
|
||||
@ -47,3 +51,18 @@ fn assignUndefinedToStruct() {
|
||||
assert(foo.x == 2);
|
||||
}
|
||||
}
|
||||
|
||||
fn assignUndefinedToStructWithMethod() {
|
||||
@setFnTest(this);
|
||||
|
||||
comptime {
|
||||
var foo: Foo = undefined;
|
||||
foo.setFooXMethod();
|
||||
assert(foo.x == 3);
|
||||
}
|
||||
{
|
||||
var foo: Foo = undefined;
|
||||
foo.setFooXMethod();
|
||||
assert(foo.x == 3);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user