aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-12-26 18:06:19 -0500
committerGitHub <noreply@github.com>2022-12-26 18:06:19 -0500
commitb0cd24f90ef159cc60c9607e9cc37af8b5bd147a (patch)
tree34447045027e830bde4aca5fa43ecfd5342997f4 /test
parent728cc73819a6511e4402498a8146854b9278285f (diff)
parent64865679cf173c024a01d158686fc1cc9965a012 (diff)
downloadzig-b0cd24f90ef159cc60c9607e9cc37af8b5bd147a.tar.gz
zig-b0cd24f90ef159cc60c9607e9cc37af8b5bd147a.zip
Merge pull request #14070 from jacobly0/issue/14032
Fix #14032
Diffstat (limited to 'test')
-rw-r--r--test/behavior/struct.zig31
1 files changed, 25 insertions, 6 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index a23294a102..2a9ea945e0 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -1420,15 +1420,34 @@ test "struct field has a pointer to an aligned version of itself" {
try expect(&e == e.next);
}
-test "struct only referenced from optional parameter/return" {
+test "struct has only one reference" {
const S = struct {
- fn f(_: ?struct { x: u8 }) void {}
- fn g() ?struct { x: u8 } {
+ fn optionalStructParam(_: ?struct { x: u8 }) void {}
+ fn errorUnionStructParam(_: error{}!struct { x: u8 }) void {}
+ fn optionalStructReturn() ?struct { x: u8 } {
return null;
}
+ fn errorUnionStructReturn() error{Foo}!struct { x: u8 } {
+ return error.Foo;
+ }
+ fn optionalComptimeIntParam(comptime x: ?comptime_int) comptime_int {
+ return x.?;
+ }
+ fn errorUnionComptimeIntParam(comptime x: error{}!comptime_int) comptime_int {
+ return x catch unreachable;
+ }
};
- const fp: *const anyopaque = &S.f;
- const gp: *const anyopaque = &S.g;
- try expect(fp != gp);
+ const optional_struct_param: *const anyopaque = &S.optionalStructParam;
+ const error_union_struct_param: *const anyopaque = &S.errorUnionStructParam;
+ try expect(optional_struct_param != error_union_struct_param);
+
+ const optional_struct_return: *const anyopaque = &S.optionalStructReturn;
+ const error_union_struct_return: *const anyopaque = &S.errorUnionStructReturn;
+ try expect(optional_struct_return != error_union_struct_return);
+
+ try expectEqual(@alignOf(struct {}), S.optionalComptimeIntParam(@alignOf(struct {})));
+ try expectEqual(@alignOf(struct { x: u8 }), S.errorUnionComptimeIntParam(@alignOf(struct { x: u8 })));
+ try expectEqual(@sizeOf(struct { x: u16 }), S.optionalComptimeIntParam(@sizeOf(struct { x: u16 })));
+ try expectEqual(@sizeOf(struct { x: u32 }), S.errorUnionComptimeIntParam(@sizeOf(struct { x: u32 })));
}