| ... | @@ -446,3 +446,121 @@ test "optional pointer in packed struct" { | ... | @@ -446,3 +446,121 @@ test "optional pointer in packed struct" { |
| 446 | const x = T{ .ptr = &n }; | 446 | const x = T{ .ptr = &n }; |
| 447 | try expect(x.ptr.? == &n); | 447 | try expect(x.ptr.? == &n); |
| 448 | } | 448 | } |
| | 449 | |
| | 450 | test "nested packed struct field access test" { |
| | 451 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO |
| | 452 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| | 453 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| | 454 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| | 455 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| | 456 | // |
| | 457 | const Vec2 = packed struct { |
| | 458 | x: f32, |
| | 459 | y: f32, |
| | 460 | }; |
| | 461 | |
| | 462 | const Vec3 = packed struct { |
| | 463 | x: f32, |
| | 464 | y: f32, |
| | 465 | z: f32, |
| | 466 | }; |
| | 467 | |
| | 468 | const NestedVec2 = packed struct { |
| | 469 | nested: Vec2, |
| | 470 | }; |
| | 471 | |
| | 472 | const NestedVec3 = packed struct { |
| | 473 | nested: Vec3, |
| | 474 | }; |
| | 475 | |
| | 476 | const vec2 = Vec2{ |
| | 477 | .x = 1.0, |
| | 478 | .y = 2.0, |
| | 479 | }; |
| | 480 | |
| | 481 | try std.testing.expectEqual(vec2.x, 1.0); |
| | 482 | try std.testing.expectEqual(vec2.y, 2.0); |
| | 483 | |
| | 484 | var vec2_o: Vec2 = undefined; |
| | 485 | const vec2_o_ptr: *Vec2 = &vec2_o; |
| | 486 | vec2_o_ptr.* = vec2; |
| | 487 | |
| | 488 | try std.testing.expectEqual(vec2_o.x, 1.0); |
| | 489 | try std.testing.expectEqual(vec2_o.y, 2.0); |
| | 490 | |
| | 491 | const nested_vec2 = NestedVec2{ |
| | 492 | .nested = Vec2{ |
| | 493 | .x = 1.0, |
| | 494 | .y = 2.0, |
| | 495 | }, |
| | 496 | }; |
| | 497 | |
| | 498 | try std.testing.expectEqual(nested_vec2.nested.x, 1.0); |
| | 499 | try std.testing.expectEqual(nested_vec2.nested.y, 2.0); |
| | 500 | |
| | 501 | var nested_o: NestedVec2 = undefined; |
| | 502 | const nested_o_ptr: *NestedVec2 = &nested_o; |
| | 503 | nested_o_ptr.* = nested_vec2; |
| | 504 | |
| | 505 | try std.testing.expectEqual(nested_o.nested.x, 1.0); |
| | 506 | try std.testing.expectEqual(nested_o.nested.y, 2.0); |
| | 507 | |
| | 508 | const vec3 = Vec3{ |
| | 509 | .x = 1.0, |
| | 510 | .y = 2.0, |
| | 511 | .z = 3.0, |
| | 512 | }; |
| | 513 | |
| | 514 | try std.testing.expectEqual(vec3.x, 1.0); |
| | 515 | try std.testing.expectEqual(vec3.y, 2.0); |
| | 516 | try std.testing.expectEqual(vec3.z, 3.0); |
| | 517 | |
| | 518 | var vec3_o: Vec3 = undefined; |
| | 519 | const vec3_o_ptr: *Vec3 = &vec3_o; |
| | 520 | vec3_o_ptr.* = vec3; |
| | 521 | |
| | 522 | try std.testing.expectEqual(vec3_o.x, 1.0); |
| | 523 | try std.testing.expectEqual(vec3_o.y, 2.0); |
| | 524 | try std.testing.expectEqual(vec3_o.z, 3.0); |
| | 525 | |
| | 526 | const nested_vec3 = NestedVec3{ |
| | 527 | .nested = Vec3{ |
| | 528 | .x = 1.0, |
| | 529 | .y = 2.0, |
| | 530 | .z = 3.0, |
| | 531 | }, |
| | 532 | }; |
| | 533 | |
| | 534 | try std.testing.expectEqual(nested_vec3.nested.x, 1.0); |
| | 535 | try std.testing.expectEqual(nested_vec3.nested.y, 2.0); |
| | 536 | try std.testing.expectEqual(nested_vec3.nested.z, 3.0); |
| | 537 | |
| | 538 | var nested_vec3_o: NestedVec3 = undefined; |
| | 539 | const nested_vec3_o_ptr: *NestedVec3 = &nested_vec3_o; |
| | 540 | nested_vec3_o_ptr.* = nested_vec3; |
| | 541 | |
| | 542 | try std.testing.expectEqual(nested_vec3_o.nested.x, 1.0); |
| | 543 | try std.testing.expectEqual(nested_vec3_o.nested.y, 2.0); |
| | 544 | try std.testing.expectEqual(nested_vec3_o.nested.z, 3.0); |
| | 545 | |
| | 546 | const hld = packed struct { |
| | 547 | c: u64, |
| | 548 | d: u32, |
| | 549 | }; |
| | 550 | |
| | 551 | const mld = packed struct { |
| | 552 | h: u64, |
| | 553 | i: u64, |
| | 554 | }; |
| | 555 | |
| | 556 | const a = packed struct { |
| | 557 | b: hld, |
| | 558 | g: mld, |
| | 559 | }; |
| | 560 | |
| | 561 | var arg = a{ .b = hld{ .c = 1, .d = 2 }, .g = mld{ .h = 6, .i = 8 } }; |
| | 562 | try std.testing.expect(arg.b.c == 1); |
| | 563 | try std.testing.expect(arg.b.d == 2); |
| | 564 | try std.testing.expect(arg.g.h == 6); |
| | 565 | try std.testing.expect(arg.g.i == 8); |
| | 566 | } |