| ... | @@ -211,7 +211,9 @@ fn testUnion() void { | ... | @@ -211,7 +211,9 @@ fn testUnion() void { |
| 211 | expect(notag_union_info.Union.tag_type == null); | 211 | expect(notag_union_info.Union.tag_type == null); |
| 212 | expect(notag_union_info.Union.layout == .Auto); | 212 | expect(notag_union_info.Union.layout == .Auto); |
| 213 | expect(notag_union_info.Union.fields.len == 2); | 213 | expect(notag_union_info.Union.fields.len == 2); |
| | 214 | expect(notag_union_info.Union.fields[0].alignment == @alignOf(void)); |
| 214 | expect(notag_union_info.Union.fields[1].field_type == u32); | 215 | expect(notag_union_info.Union.fields[1].field_type == u32); |
| | 216 | expect(notag_union_info.Union.fields[1].alignment == @alignOf(u32)); |
| 215 | | 217 | |
| 216 | const TestExternUnion = extern union { | 218 | const TestExternUnion = extern union { |
| 217 | foo: *c_void, | 219 | foo: *c_void, |
| ... | @@ -229,13 +231,18 @@ test "type info: struct info" { | ... | @@ -229,13 +231,18 @@ test "type info: struct info" { |
| 229 | } | 231 | } |
| 230 | | 232 | |
| 231 | fn testStruct() void { | 233 | fn testStruct() void { |
| | 234 | const unpacked_struct_info = @typeInfo(TestUnpackedStruct); |
| | 235 | expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32)); |
| | 236 | |
| 232 | const struct_info = @typeInfo(TestStruct); | 237 | const struct_info = @typeInfo(TestStruct); |
| 233 | expect(struct_info == .Struct); | 238 | expect(struct_info == .Struct); |
| 234 | expect(struct_info.Struct.layout == .Packed); | 239 | expect(struct_info.Struct.layout == .Packed); |
| 235 | expect(struct_info.Struct.fields.len == 4); | 240 | expect(struct_info.Struct.fields.len == 4); |
| | 241 | expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize)); |
| 236 | expect(struct_info.Struct.fields[2].field_type == *TestStruct); | 242 | expect(struct_info.Struct.fields[2].field_type == *TestStruct); |
| 237 | expect(struct_info.Struct.fields[2].default_value == null); | 243 | expect(struct_info.Struct.fields[2].default_value == null); |
| 238 | expect(struct_info.Struct.fields[3].default_value.? == 4); | 244 | expect(struct_info.Struct.fields[3].default_value.? == 4); |
| | 245 | expect(struct_info.Struct.fields[3].alignment == 1); |
| 239 | expect(struct_info.Struct.decls.len == 2); | 246 | expect(struct_info.Struct.decls.len == 2); |
| 240 | expect(struct_info.Struct.decls[0].is_pub); | 247 | expect(struct_info.Struct.decls[0].is_pub); |
| 241 | expect(!struct_info.Struct.decls[0].data.Fn.is_extern); | 248 | expect(!struct_info.Struct.decls[0].data.Fn.is_extern); |
| ... | @@ -244,8 +251,12 @@ fn testStruct() void { | ... | @@ -244,8 +251,12 @@ fn testStruct() void { |
| 244 | expect(struct_info.Struct.decls[0].data.Fn.fn_type == fn (*const TestStruct) void); | 251 | expect(struct_info.Struct.decls[0].data.Fn.fn_type == fn (*const TestStruct) void); |
| 245 | } | 252 | } |
| 246 | | 253 | |
| | 254 | const TestUnpackedStruct = struct { |
| | 255 | fieldA: u32 = 4, |
| | 256 | }; |
| | 257 | |
| 247 | const TestStruct = packed struct { | 258 | const TestStruct = packed struct { |
| 248 | fieldA: usize, | 259 | fieldA: usize align(2 * @alignOf(usize)), |
| 249 | fieldB: void, | 260 | fieldB: void, |
| 250 | fieldC: *Self, | 261 | fieldC: *Self, |
| 251 | fieldD: u32 = 4, | 262 | fieldD: u32 = 4, |