| author | |
| committer | |
| log | 687a7d38a00e187a75c43617d8de6fefaffb5449 |
| tree | 8adf485f0c6213d3f89b37a535df9a2a21176c45 |
| parent | edc842ff18e19d8c07cde1199f72903356fbf77f |
* Support comparison between implicitly casted array pointer and slice.
* Support comparison between slices with different value tags.
Closes #127002 files changed, 36 insertions(+), 0 deletions(-)
src/value.zig+22| ... | @@ -2260,6 +2260,28 @@ pub const Value = extern union { | ... | @@ -2260,6 +2260,28 @@ pub const Value = extern union { |
| 2260 | } | 2260 | } |
| 2261 | return true; | 2261 | return true; |
| 2262 | }, | 2262 | }, |
| 2263 | .Pointer => switch (ty.ptrSize()) { | ||
| 2264 | .Slice => { | ||
| 2265 | const a_len = switch (a_ty.ptrSize()) { | ||
| 2266 | .Slice => a.sliceLen(mod), | ||
| 2267 | .One => a_ty.childType().arrayLen(), | ||
| 2268 | else => unreachable, | ||
| 2269 | }; | ||
| 2270 | if (a_len != b.sliceLen(mod)) { | ||
| 2271 | return false; | ||
| 2272 | } | ||
| 2273 | |||
| 2274 | var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined; | ||
| 2275 | const ptr_ty = ty.slicePtrFieldType(&ptr_buf); | ||
| 2276 | const a_ptr = switch (a_ty.ptrSize()) { | ||
| 2277 | .Slice => a.slicePtr(), | ||
| 2278 | .One => a, | ||
| 2279 | else => unreachable, | ||
| 2280 | }; | ||
| 2281 | return try eqlAdvanced(a_ptr, ptr_ty, b.slicePtr(), ptr_ty, mod, sema_kit); | ||
| 2282 | }, | ||
| 2283 | .Many, .C, .One => {}, | ||
| 2284 | }, | ||
| 2263 | .Struct => { | 2285 | .Struct => { |
| 2264 | // A struct can be represented with one of: | 2286 | // A struct can be represented with one of: |
| 2265 | // .empty_struct_value, | 2287 | // .empty_struct_value, |
test/behavior/generics.zig+14| ... | @@ -382,3 +382,17 @@ test "generic struct as parameter type" { | ... | @@ -382,3 +382,17 @@ test "generic struct as parameter type" { |
| 382 | try S.doTheTest(u32, .{ .int = 123 }); | 382 | try S.doTheTest(u32, .{ .int = 123 }); |
| 383 | try S.doTheTest2(i32, .{ .int = 456 }); | 383 | try S.doTheTest2(i32, .{ .int = 456 }); |
| 384 | } | 384 | } |
| 385 | |||
| 386 | test "slice as parameter type" { | ||
| 387 | const S = struct { | ||
| 388 | fn internComptimeString(comptime str: []const u8) *const []const u8 { | ||
| 389 | return &struct { | ||
| 390 | const intern: []const u8 = str; | ||
| 391 | }.intern; | ||
| 392 | } | ||
| 393 | }; | ||
| 394 | |||
| 395 | const source_a = "this is a string"; | ||
| 396 | try expect(S.internComptimeString(source_a[1..2]) == S.internComptimeString(source_a[1..2])); | ||
| 397 | try expect(S.internComptimeString(source_a[2..4]) != S.internComptimeString(source_a[5..7])); | ||
| 398 | } |