commit 16302578d5a0ca226c7db76bc8e39574dea1dc1d (tree) parent 2cf27c571880a607401dca181f8103e855d0c46d Author: Andrew Kelley <andrew@ziglang.org> Date: Sat, 4 Mar 2023 14:04:58 -0700 add behavior test case for previous commit Diffstat:
| M | test/behavior/slice.zig | | | 15 | +++++++++++++++ |
1 file changed, 15 insertions(+), 0 deletions(-)
diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig @@ -747,3 +747,18 @@ test "slice decays to many pointer" { const p: [*:0]const u8 = buf[0..7 :0]; try expectEqualStrings(buf[0..7], std.mem.span(p)); } + +test "write through pointer to optional slice arg" { + const S = struct { + fn bar(foo: *?[]const u8) !void { + foo.* = try baz(); + } + + fn baz() ![]const u8 { + return "ok"; + } + }; + var foo: ?[]const u8 = null; + try S.bar(&foo); + try expectEqualStrings(foo.?, "ok"); +}