Skip to content

vlib: fix new_int for vlib#25351

Merged
spytheman merged 4 commits into
vlang:masterfrom
kbkpbot:fix-new-int-vlib-2
Sep 19, 2025
Merged

vlib: fix new_int for vlib#25351
spytheman merged 4 commits into
vlang:masterfrom
kbkpbot:fix-new-int-vlib-2

Conversation

@kbkpbot

@kbkpbot kbkpbot commented Sep 19, 2025

Copy link
Copy Markdown
Contributor

Fix new_int for vlib working.

@vlang vlang deleted a comment from huly-for-github Bot Sep 19, 2025
Comment thread vlib/builtin/int_test.v
Comment on lines +20 to +24
assert int(u32(2147483648)).str() == $if new_int ? && x64 {
'2147483648'
} $else {
'-2147483648'
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it would have been clearer, if it was:

Suggested change
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:

Image

@spytheman spytheman Sep 19, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +16 to +20
$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]!
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, this is much better!

Comment on lines 20 to 32
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: '

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }) }

@spytheman spytheman Sep 19, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@spytheman spytheman Sep 19, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread vlib/v/tests/structs/struct_generic_sizeof_test.v
Comment thread vlib/v/tests/c_array_test.c.v

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good work.

@spytheman spytheman merged commit dddbacb into vlang:master Sep 19, 2025
82 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants