diff --git a/src/AstGen.zig b/src/AstGen.zig index de512e5bdb..cbfe1a3adb 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -3123,10 +3123,10 @@ fn varDecl( if (nodeMayAppendToErrorTrace(tree, var_decl.ast.init_node)) _ = try gz.addSaveErrRetIndex(.{ .if_of_error_type = init_inst }); - if (resolve_inferred_alloc != .none) { + const const_ptr = if (resolve_inferred_alloc != .none) p: { _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node); - } - const const_ptr = try gz.addUnNode(.make_ptr_const, var_ptr, node); + break :p var_ptr; + } else try gz.addUnNode(.make_ptr_const, var_ptr, node); try gz.addDbgVar(.dbg_var_ptr, ident_name, const_ptr); @@ -3533,7 +3533,9 @@ fn assignDestructureMaybeDecls( else => unreachable, }; // If the alloc was const, make it const. - const var_ptr = if (is_const) make_const: { + const var_ptr = if (is_const and full.ast.type_node != 0) make_const: { + // Note that we don't do this if type_node == 0 since `resolve_inferred_alloc` + // handles it for us. break :make_const try gz.addUnNode(.make_ptr_const, raw_ptr, node); } else raw_ptr; const name_token = full.ast.mut_token + 1; diff --git a/src/Zir.zig b/src/Zir.zig index 973177c1b0..c72228a42f 100644 --- a/src/Zir.zig +++ b/src/Zir.zig @@ -997,8 +997,9 @@ pub const Inst = struct { /// is the allocation that needs to have its type inferred. /// Uses the `un_node` field. The AST node is the var decl. resolve_inferred_alloc, - /// Turns a pointer coming from an `alloc`, `alloc_inferred`, `alloc_inferred_comptime` or - /// `Extended.alloc` into a constant version of the same pointer. + /// Turns a pointer coming from an `alloc` or `Extended.alloc` into a constant + /// version of the same pointer. For inferred allocations this is instead implicitly + /// handled by the `resolve_inferred_alloc` instruction. /// Uses the `un_node` union field. make_ptr_const,