diff --git a/src/AstGen.zig b/src/AstGen.zig index ae1c6be0da..0b0de11ea9 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -698,7 +698,13 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr .lhs = lhs, .start = start, }); - return rvalue(gz, rl, result, node); + switch (rl) { + .ref, .none_or_ref => return result, + else => { + const dereffed = try gz.addUnNode(.load, result, node); + return rvalue(gz, rl, dereffed, node); + }, + } }, .slice => { const lhs = try expr(gz, scope, .ref, node_datas[node].lhs); @@ -710,7 +716,13 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr .start = start, .end = end, }); - return rvalue(gz, rl, result, node); + switch (rl) { + .ref, .none_or_ref => return result, + else => { + const dereffed = try gz.addUnNode(.load, result, node); + return rvalue(gz, rl, dereffed, node); + }, + } }, .slice_sentinel => { const lhs = try expr(gz, scope, .ref, node_datas[node].lhs); @@ -724,7 +736,13 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr .end = end, .sentinel = sentinel, }); - return rvalue(gz, rl, result, node); + switch (rl) { + .ref, .none_or_ref => return result, + else => { + const dereffed = try gz.addUnNode(.load, result, node); + return rvalue(gz, rl, dereffed, node); + }, + } }, .deref => { diff --git a/src/Zir.zig b/src/Zir.zig index 2110122580..2092a7b5e4 100644 --- a/src/Zir.zig +++ b/src/Zir.zig @@ -495,12 +495,15 @@ pub const Inst = struct { /// Uses the `ptr_type` union field. ptr_type, /// Slice operation `lhs[rhs..]`. No sentinel and no end offset. + /// Returns a pointer to the subslice. /// Uses the `pl_node` field. AST node is the slice syntax. Payload is `SliceStart`. slice_start, /// Slice operation `array_ptr[start..end]`. No sentinel. + /// Returns a pointer to the subslice. /// Uses the `pl_node` field. AST node is the slice syntax. Payload is `SliceEnd`. slice_end, /// Slice operation `array_ptr[start..end:sentinel]`. + /// Returns a pointer to the subslice. /// Uses the `pl_node` field. AST node is the slice syntax. Payload is `SliceSentinel`. slice_sentinel, /// Write a value to a pointer. For loading, see `load`.