| 1 | const expectEqual = @import("std").testing.expectEqual; |
| 2 | test "result type propagates through struct initializer" { |
| 3 | const S = struct { x: u32 }; |
| 4 | const val: u64 = 123; |
| 5 | const s: S = .{ .x = @intCast(val) }; |
| 6 | // .{ .x = @intCast(val) } has result type `S` due to the type annotation |
| 7 | // @intCast(val) has result type `u32` due to the type of the field `S.x` |
| 8 | // val has no result type, as it is permitted to be any integer type |
| 9 | try expectEqual(@as(u32, 123), s.x); |
| 10 | } |
| 11 | |
| 12 | // test |