| author | |
| committer | |
| log | 7d0b6956c0935807f0e5862c45da857e8e065c6b |
| tree | d2b3df54d4bf185e326d4b4363958b5ed210698c |
| parent | 2c434cddd6624cfd5c71f081b9445936d25c7703 |
We must resolve the type fully so that pointer children (i.e. slices)
are resolved. Additionally, we must resolve even if we can know the
value at comptime because the `alloc_inferred` ZIR always produces a
constant in the AIR.
Fixes #111813 files changed, 38 insertions(+), 1 deletions(-)
src/Sema.zig+6-1| ... | ... | @@ -2672,11 +2672,16 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 2672 | 2672 | // ZIR handles it later, so we can just use the ty ref here. |
| 2673 | 2673 | air_datas[ptr_inst].ty_pl.ty = air_datas[bitcast_inst].ty_op.ty; |
| 2674 | 2674 | |
| 2675 | // Unless the block is comptime, `alloc_inferred` always produces | |
| 2676 | // a runtime constant. The final inferred type needs to be | |
| 2677 | // fully resolved so it can be lowered in codegen. | |
| 2678 | try sema.resolveTypeFully(block, ty_src, final_elem_ty); | |
| 2679 | ||
| 2675 | 2680 | return; |
| 2676 | 2681 | } |
| 2677 | 2682 | |
| 2678 | 2683 | try sema.requireRuntimeBlock(block, src); |
| 2679 | try sema.resolveTypeLayout(block, ty_src, final_elem_ty); | |
| 2684 | try sema.resolveTypeFully(block, ty_src, final_elem_ty); | |
| 2680 | 2685 | |
| 2681 | 2686 | // Change it to a normal alloc. |
| 2682 | 2687 | sema.air_instructions.set(ptr_inst, .{ |
test/behavior.zig+1| ... | ... | @@ -66,6 +66,7 @@ test { |
| 66 | 66 | _ = @import("behavior/bugs/11046.zig"); |
| 67 | 67 | _ = @import("behavior/bugs/11139.zig"); |
| 68 | 68 | _ = @import("behavior/bugs/11165.zig"); |
| 69 | _ = @import("behavior/bugs/11181.zig"); | |
| 69 | 70 | _ = @import("behavior/call.zig"); |
| 70 | 71 | _ = @import("behavior/cast.zig"); |
| 71 | 72 | _ = @import("behavior/comptime_memory.zig"); |
test/behavior/bugs/11181.zig created+31| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | ||
| 3 | test "const inferred array of slices" { | |
| 4 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | |
| 5 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 6 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 7 | ||
| 8 | const T = struct { v: bool }; | |
| 9 | ||
| 10 | const decls = [_][]const T{ | |
| 11 | &[_]T{ | |
| 12 | .{ .v = false }, | |
| 13 | }, | |
| 14 | }; | |
| 15 | _ = decls; | |
| 16 | } | |
| 17 | ||
| 18 | test "var inferred array of slices" { | |
| 19 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | |
| 20 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 21 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 22 | ||
| 23 | const T = struct { v: bool }; | |
| 24 | ||
| 25 | var decls = [_][]const T{ | |
| 26 | &[_]T{ | |
| 27 | .{ .v = false }, | |
| 28 | }, | |
| 29 | }; | |
| 30 | _ = decls; | |
| 31 | } |