fix ability to call method on variable at compile time

This commit is contained in:
Andrew Kelley 2017-02-02 15:03:00 -05:00
parent 2b88441295
commit 8b1c6d8b76
2 changed files with 28 additions and 3 deletions

View File

@ -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;

View File

@ -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);
}
}