mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
parent
a0de077600
commit
187f0c1e26
2 changed files with 21 additions and 1 deletions
|
|
@ -4279,7 +4279,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
|
|||
const const_ptr_ty = try sema.makePtrTyConst(final_ptr_ty);
|
||||
const new_const_ptr = try mod.getCoerced(Value.fromInterned(ptr_val), const_ptr_ty);
|
||||
|
||||
// Remap the ZIR oeprand to the resolved pointer value
|
||||
// Remap the ZIR operand to the resolved pointer value
|
||||
sema.inst_map.putAssumeCapacity(inst_data.operand.toIndex().?, Air.internedToRef(new_const_ptr.toIntern()));
|
||||
|
||||
// Unless the block is comptime, `alloc_inferred` always produces
|
||||
|
|
@ -4305,6 +4305,11 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
|
|||
.data = .{ .ty = final_ptr_ty },
|
||||
});
|
||||
|
||||
if (ia1.is_const) {
|
||||
// Remap the ZIR operand to the pointer const
|
||||
sema.inst_map.putAssumeCapacity(inst_data.operand.toIndex().?, try sema.makePtrConst(block, ptr));
|
||||
}
|
||||
|
||||
// Now we need to go back over all the store instructions, and do the logic as if
|
||||
// the new result ptr type was available.
|
||||
|
||||
|
|
|
|||
15
test/cases/compile_errors/assign_to_constant_destructure.zig
Normal file
15
test/cases/compile_errors/assign_to_constant_destructure.zig
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
export fn a() void {
|
||||
const S = struct {
|
||||
fn b() struct { usize, usize } {
|
||||
return .{ 0, 0 };
|
||||
}
|
||||
};
|
||||
const c, _ = S.b();
|
||||
c += 10;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :8:7: error: cannot assign to constant
|
||||
Loading…
Add table
Reference in a new issue