| ... | @@ -3780,6 +3780,21 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -3780,6 +3780,21 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3780 | return sema.analyzeDeclRef(try anon_decl.finish(elem_ty, store_val, ptr_info.flags.alignment)); | 3780 | return sema.analyzeDeclRef(try anon_decl.finish(elem_ty, store_val, ptr_info.flags.alignment)); |
| 3781 | } | 3781 | } |
| 3782 | | 3782 | |
| | 3783 | // If this is already a comptime-mutable allocation, we don't want to emit an error - the stores |
| | 3784 | // were already performed at comptime! Just make the pointer constant as normal. |
| | 3785 | implicit_ct: { |
| | 3786 | const ptr_val = try sema.resolveMaybeUndefVal(alloc) orelse break :implicit_ct; |
| | 3787 | if (ptr_val.isComptimeMutablePtr(mod)) break :implicit_ct; |
| | 3788 | return sema.makePtrConst(block, alloc); |
| | 3789 | } |
| | 3790 | |
| | 3791 | if (try sema.typeRequiresComptime(elem_ty)) { |
| | 3792 | // The value was initialized through RLS, so we didn't detect the runtime condition earlier. |
| | 3793 | // TODO: source location of runtime control flow |
| | 3794 | const init_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| | 3795 | return sema.fail(block, init_src, "value with comptime-only type '{}' depends on runtime control flow", .{elem_ty.fmt(mod)}); |
| | 3796 | } |
| | 3797 | |
| 3783 | return sema.makePtrConst(block, alloc); | 3798 | return sema.makePtrConst(block, alloc); |
| 3784 | } | 3799 | } |
| 3785 | | 3800 | |