diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-07 16:01:13 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-07 16:01:13 -0700 |
| commit | 3df19b765d3b33cfda43b875adb714487bfb8c6b (patch) | |
| tree | b8325170ca693b5c94a569a256449a4dde0e6064 /src | |
| parent | 76335bc7badd41af0ebb7dd196e1550d7e99d8e7 (diff) | |
| download | zig-3df19b765d3b33cfda43b875adb714487bfb8c6b.tar.gz zig-3df19b765d3b33cfda43b875adb714487bfb8c6b.zip | |
AstGen: make array literals work like struct literals
Now, array literals will emit a coerce_result_ptr ZIR instruction just
like struct literals do. This makes for another passing behavior test case.
Diffstat (limited to 'src')
| -rw-r--r-- | src/AstGen.zig | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index 423e11e582..614930734a 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -1282,10 +1282,10 @@ fn arrayInitExpr( } }, .ptr, .inferred_ptr => |ptr_inst| { - return arrayInitExprRlPtr(gz, scope, node, array_init.ast.elements, ptr_inst); + return arrayInitExprRlPtr(gz, scope, rl, node, ptr_inst, array_init.ast.elements, types.array); }, .block_ptr => |block_gz| { - return arrayInitExprRlPtr(gz, scope, node, array_init.ast.elements, block_gz.rl_ptr); + return arrayInitExprRlPtr(gz, scope, rl, node, block_gz.rl_ptr, array_init.ast.elements, types.array); }, } } @@ -1341,9 +1341,29 @@ fn arrayInitExprRlTy( fn arrayInitExprRlPtr( gz: *GenZir, scope: *Scope, + rl: ResultLoc, node: Ast.Node.Index, + result_ptr: Zir.Inst.Ref, elements: []const Ast.Node.Index, + array_ty: Zir.Inst.Ref, +) InnerError!Zir.Inst.Ref { + if (array_ty == .none) { + return arrayInitExprRlPtrInner(gz, scope, node, result_ptr, elements); + } + + var as_scope = try gz.makeCoercionScope(scope, array_ty, result_ptr); + defer as_scope.instructions.deinit(gz.astgen.gpa); + + const result = try arrayInitExprRlPtrInner(&as_scope, scope, node, as_scope.rl_ptr, elements); + return as_scope.finishCoercion(gz, rl, node, result, array_ty); +} + +fn arrayInitExprRlPtrInner( + gz: *GenZir, + scope: *Scope, + node: Ast.Node.Index, result_ptr: Zir.Inst.Ref, + elements: []const Ast.Node.Index, ) InnerError!Zir.Inst.Ref { const astgen = gz.astgen; const gpa = astgen.gpa; |
