@@ -1094,3 +1094,44 @@ test "@splat zero-length array" {
1094
1094
try S .doTheTest (? * anyopaque , null );
1095
1095
try comptime S .doTheTest (? * anyopaque , null );
1096
1096
}
1097
+
1098
+ test "initialize slice with reference to empty array initializer" {
1099
+ const a : []const u8 = &.{};
1100
+ comptime assert (a .len == 0 );
1101
+ }
1102
+
1103
+ test "initialize many-pointer with reference to empty array initializer" {
1104
+ const a : [* ]const u8 = &.{};
1105
+ _ = a ; // nothing meaningful to test; points to zero bits
1106
+ }
1107
+
1108
+ test "initialize sentinel-terminated slice with reference to empty array initializer" {
1109
+ const a : [:0 ]const u8 = &.{};
1110
+ comptime assert (a .len == 0 );
1111
+ comptime assert (a [0 ] == 0 );
1112
+ }
1113
+
1114
+ test "initialize sentinel-terminated many-pointer with reference to empty array initializer" {
1115
+ const a : [* :0 ]const u8 = &.{};
1116
+ comptime assert (a [0 ] == 0 );
1117
+ }
1118
+
1119
+ test "pass pointer to empty array initializer to anytype parameter" {
1120
+ const S = struct {
1121
+ fn TypeOf (x : anytype ) type {
1122
+ return @TypeOf (x );
1123
+ }
1124
+ };
1125
+ comptime assert (S .TypeOf (&.{}) == @TypeOf (&.{}));
1126
+ }
1127
+
1128
+ test "initialize pointer to anyopaque with reference to empty array initializer" {
1129
+ const ptr : * const anyopaque = &.{};
1130
+ // The above acts like an untyped initializer, since the `.{}` has no result type.
1131
+ // So, `ptr` points in memory to an empty tuple (`@TypeOf(.{})`).
1132
+ const casted : * const @TypeOf (.{}) = @alignCast (@ptrCast (ptr ));
1133
+ const loaded = casted .* ;
1134
+ // `val` should be a `@TypeOf(.{})`, as expected.
1135
+ // We can't check the value, but it's zero-bit, so the type matching is good enough.
1136
+ comptime assert (@TypeOf (loaded ) == @TypeOf (.{}));
1137
+ }
0 commit comments