| author | |
| committer | |
| log | f43ea43ac920d3fbd629175e4e7fbe4309c6eab5 |
| tree | d0edfe385cedffe26a15c325421c5029a1081977 |
| parent | 4fc2acdaa4f2b649b17ddf958d2608abc4787a4e |
Closes #122792 files changed, 23 insertions(+), 15 deletions(-)
src/value.zig+3-15| ... | ... | @@ -2292,25 +2292,13 @@ pub const Value = extern union { |
| 2292 | 2292 | } |
| 2293 | 2293 | }, |
| 2294 | 2294 | .Struct => { |
| 2295 | if (ty.isTupleOrAnonStruct()) { | |
| 2296 | const fields = ty.tupleFields(); | |
| 2297 | for (fields.values) |field_val, i| { | |
| 2298 | field_val.hash(fields.types[i], hasher, mod); | |
| 2299 | } | |
| 2300 | return; | |
| 2301 | } | |
| 2302 | const fields = ty.structFields().values(); | |
| 2303 | if (fields.len == 0) return; | |
| 2304 | 2295 | switch (val.tag()) { |
| 2305 | .empty_struct_value => { | |
| 2306 | for (fields) |field| { | |
| 2307 | field.default_val.hash(field.ty, hasher, mod); | |
| 2308 | } | |
| 2309 | }, | |
| 2296 | .empty_struct_value => {}, | |
| 2310 | 2297 | .aggregate => { |
| 2311 | 2298 | const field_values = val.castTag(.aggregate).?.data; |
| 2312 | 2299 | for (field_values) |field_val, i| { |
| 2313 | field_val.hash(fields[i].ty, hasher, mod); | |
| 2300 | const field_ty = ty.structFieldType(i); | |
| 2301 | field_val.hash(field_ty, hasher, mod); | |
| 2314 | 2302 | } |
| 2315 | 2303 | }, |
| 2316 | 2304 | else => unreachable, |
test/behavior/tuple.zig+20| ... | ... | @@ -255,3 +255,23 @@ test "initializing anon struct with mixed comptime-runtime fields" { |
| 255 | 255 | var a: T = .{ .foo = -1234, .bar = x + 1 }; |
| 256 | 256 | _ = a; |
| 257 | 257 | } |
| 258 | ||
| 259 | test "tuple in tuple passed to generic function" { | |
| 260 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | |
| 261 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 262 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 263 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | |
| 264 | ||
| 265 | const S = struct { | |
| 266 | fn pair(x: f32, y: f32) std.meta.Tuple(&.{ f32, f32 }) { | |
| 267 | return .{ x, y }; | |
| 268 | } | |
| 269 | ||
| 270 | fn foo(x: anytype) !void { | |
| 271 | try expect(x[0][0] == 1.5); | |
| 272 | try expect(x[0][1] == 2.5); | |
| 273 | } | |
| 274 | }; | |
| 275 | const x = comptime S.pair(1.5, 2.5); | |
| 276 | try S.foo(.{x}); | |
| 277 | } |