Commit 1bca8e693d
src/ir.cpp
@@ -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;
- init_array_type_source_node = parent_result_loc->source_instruction->source_node;
+ 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),
test/stage1/behavior/union.zig
@@ -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();