vlib: fix new_int for vlib#25351
Conversation
| assert int(u32(2147483648)).str() == $if new_int ? && x64 { | ||
| '2147483648' | ||
| } $else { | ||
| '-2147483648' | ||
| } |
There was a problem hiding this comment.
I think, it would have been clearer, if it was:
| assert int(u32(2147483648)).str() == $if new_int ? && x64 { | |
| '2147483648' | |
| } $else { | |
| '-2147483648' | |
| } | |
| $if new_int ? && x64 { | |
| assert int(u32(2147483648)).str() == '2147483648' | |
| } $else { | |
| assert int(u32(2147483648)).str() == '-2147483648' | |
| } |
because then the potentially failing assertion will be simpler and easier to diagnose from just the output.
For comparison:
There was a problem hiding this comment.
As you can see, in the second version, you can immediately see that the (potentially) failing assertion is the one on line 23, and the expected value right away, while in the first case, you use the full condition + the comptime logic and have to interpret it, before understanding which case it was, and what was the actual expected value.
| $if new_int ? && x64 { | ||
| assert c == [u8(1), 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0]! | ||
| } $else { | ||
| assert c == [u8(1), 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0]! | ||
| } |
There was a problem hiding this comment.
nice, this is much better!
| fn test_main() { | ||
| assert d(Value(0)) == 'Value is number or byte array, size=4 0' | ||
| assert d(Value(0)) == $if new_int ? && x64 { | ||
| 'Value is number or byte array, size=8 0' | ||
| } $else { | ||
| 'Value is number or byte array, size=4 0' | ||
| } | ||
| assert d(Value(i64(1))) == 'Value is number or byte array, size=8 1' | ||
| assert d(Value(u64(2))) == 'Value is number or byte array, size=8 2' | ||
| assert d(Value([u8(1), 2])) == 'Value is number or byte array, size=32 [1, 2]' | ||
| assert d(Value([u8(1), 2])) == $if new_int ? && x64 { | ||
| 'Value is number or byte array, size=48 [1, 2]' | ||
| } $else { | ||
| 'Value is number or byte array, size=32 [1, 2]' | ||
| } | ||
| assert d(Value('')) == 'Value is string: ' |
There was a problem hiding this comment.
imho just change int to i32 in the sumtype here, because that way the diff will be smaller, and the test is otherwise unrelated to the int -> isize change.
| b[0] = 1 | ||
| b[1] = 2 | ||
| mut a := unsafe { memdup(b, 8) } | ||
| mut a := unsafe { memdup(b, $if new_int ? && x64 { 16 } $else { 8 }) } |
There was a problem hiding this comment.
same, imho just change int to i32 here - the test does not need to be concerned with the new_int change
| fn test_generic_fn_variable() { | ||
| r1 := f[int]() | ||
| println(r1) | ||
| assert r1 == 4 |
There was a problem hiding this comment.
same, changing int to i32 will produce a simpler diff, that will not have to be edited out again, when new_int becomes the default, and the test is not directly related to the sizes of the integers; they are used here just as a proxy that the comptime generic worked
Fix
new_intforvlibworking.