fix anon literal used with return result loc

This commit is contained in:
Andrew Kelley 2019-11-11 13:18:16 -05:00
parent d4e6a6d5e2
commit 1bca8e693d
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 14 additions and 2 deletions

View File

@ -6151,7 +6151,11 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
init_array_type_source_node = container_type->source_node;
} else {
child_result_loc = parent_result_loc;
if (parent_result_loc->source_instruction != nullptr) {
init_array_type_source_node = parent_result_loc->source_instruction->source_node;
} else {
init_array_type_source_node = node;
}
}
switch (kind) {
@ -15935,6 +15939,10 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
instruction->result_loc->source_instruction->child);
if (type_is_invalid(implicit_elem_type))
return ira->codegen->invalid_instruction;
} else if (instruction->result_loc->id == ResultLocIdReturn) {
implicit_elem_type = ira->explicit_return_type;
if (type_is_invalid(implicit_elem_type))
return ira->codegen->invalid_instruction;
} else {
Buf *bare_name = buf_alloc();
Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),

View File

@ -559,10 +559,14 @@ test "anonymous union literal syntax" {
fn doTheTest() void {
var i: Number = .{.int = 42};
var f: Number = .{.float = 12.34};
var f = makeNumber();
expect(i.int == 42);
expect(f.float == 12.34);
}
fn makeNumber() Number {
return .{.float = 12.34};
}
};
S.doTheTest();
comptime S.doTheTest();