From fd4d28b7b6eb98ef64ad26132d255b72572a762e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kr=C3=BCger?= <45282134+UweKrueger@users.noreply.github.com> Date: Sun, 24 May 2020 21:07:32 +0200 Subject: [PATCH] tests: update for stricter type checks --- vlib/builtin/int_test.v | 2 +- vlib/clipboard/clipboard_linux.c.v | 2 +- vlib/crypto/aes/block_generic.v | 4 ++-- vlib/crypto/aes/const.v | 16 ++++++------- vlib/crypto/md5/md5.v | 4 ++-- vlib/encoding/base64/base64.v | 6 ++--- vlib/encoding/base64/base64_memory_test.v | 4 ++-- vlib/encoding/utf8/utf8_util.v | 4 ++-- vlib/glm/glm.v | 20 ++++++++-------- vlib/math/bits/bits_test.v | 14 +++++------ vlib/math/fractions/approximations.v | 6 ++--- vlib/math/math_test.v | 2 +- vlib/regex/regex.v | 2 +- vlib/regex/regex_test.v | 6 ++--- vlib/time/time_test.v | 2 +- vlib/v/gen/cgen.v | 4 ++-- vlib/v/tests/complex_assign_test.v | 2 +- vlib/v/tests/map_to_string_test.v | 1 + .../v/tests/match_expression_for_types_test.v | 4 ++-- vlib/v/tests/shift_test.v | 24 ++++++++++--------- .../v/tests/string_interpolation_array_test.v | 4 ++-- .../tests/string_interpolation_struct_test.v | 2 +- vlib/v/tests/typeof_simple_types_test.v | 6 +++-- vlib/v/tests/typeof_test.v | 19 ++++++++++----- vlib/vweb/assets/assets.v | 4 ++-- 25 files changed, 88 insertions(+), 76 deletions(-) diff --git a/vlib/builtin/int_test.v b/vlib/builtin/int_test.v index 2381d43b9d..ff4bc9a2ba 100644 --- a/vlib/builtin/int_test.v +++ b/vlib/builtin/int_test.v @@ -31,7 +31,7 @@ fn test_float_equal_operator() { assert a.gebit(1) assert -1 == 1 * -1 assert -1.0 == 1.0 * -1.0 - a = f64(1) + a = 1 a += 0.000001 a -= 0.000001 assert a == f32(1.0) diff --git a/vlib/clipboard/clipboard_linux.c.v b/vlib/clipboard/clipboard_linux.c.v index 7b252a6fcb..564e56b754 100644 --- a/vlib/clipboard/clipboard_linux.c.v +++ b/vlib/clipboard/clipboard_linux.c.v @@ -128,7 +128,7 @@ pub struct Clipboard { struct Property{ actual_type C.Atom actual_format int - nitems int + nitems u64 data byteptr } diff --git a/vlib/crypto/aes/block_generic.v b/vlib/crypto/aes/block_generic.v index c41edf8f52..f3f833d97d 100644 --- a/vlib/crypto/aes/block_generic.v +++ b/vlib/crypto/aes/block_generic.v @@ -61,7 +61,7 @@ fn encrypt_block_generic(xk []u32, dst, src []byte) { mut t1 := u32(0) mut t2 := u32(0) mut t3 := u32(0) - for r in 0..nr { + for _ in 0..nr { t0 = xk[k+0] ^ te0[byte(s0>>24)] ^ te1[byte(s1>>16)] ^ te2[byte(s2>>8)] ^ u32(te3[byte(s3)]) t1 = xk[k+1] ^ te0[byte(s1>>24)] ^ te1[byte(s2>>16)] ^ te2[byte(s3>>8)] ^ u32(te3[byte(s0)]) t2 = xk[k+2] ^ te0[byte(s2>>24)] ^ te1[byte(s3>>16)] ^ te2[byte(s0>>8)] ^ u32(te3[byte(s1)]) @@ -113,7 +113,7 @@ fn decrypt_block_generic(xk []u32, dst, src []byte) { mut t1 := u32(0) mut t2 := u32(0) mut t3 := u32(0) - for r in 0..nr { + for _ in 0..nr { t0 = xk[k+0] ^ td0[byte(s0>>24)] ^ td1[byte(s3>>16)] ^ td2[byte(s2>>8)] ^ u32(td3[byte(s1)]) t1 = xk[k+1] ^ td0[byte(s1>>24)] ^ td1[byte(s0>>16)] ^ td2[byte(s3>>8)] ^ u32(td3[byte(s2)]) t2 = xk[k+2] ^ td0[byte(s2>>24)] ^ td1[byte(s1>>16)] ^ td2[byte(s0>>8)] ^ u32(td3[byte(s3)]) diff --git a/vlib/crypto/aes/const.v b/vlib/crypto/aes/const.v index d03f3b9a86..4cf0c60c60 100644 --- a/vlib/crypto/aes/const.v +++ b/vlib/crypto/aes/const.v @@ -96,7 +96,7 @@ const ( const ( te0 = [ - 0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d, 0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554, + u32(0xc66363a5), 0xf87c7c84, 0xee777799, 0xf67b7b8d, 0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554, 0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d, 0xe7fefe19, 0xb5d7d762, 0x4dababe6, 0xec76769a, 0x8fcaca45, 0x1f82829d, 0x89c9c940, 0xfa7d7d87, 0xeffafa15, 0xb25959eb, 0x8e4747c9, 0xfbf0f00b, 0x41adadec, 0xb3d4d467, 0x5fa2a2fd, 0x45afafea, 0x239c9cbf, 0x53a4a4f7, 0xe4727296, 0x9bc0c05b, @@ -130,7 +130,7 @@ const ( 0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11, 0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a, ] te1 = [ - 0xa5c66363, 0x84f87c7c, 0x99ee7777, 0x8df67b7b, 0x0dfff2f2, 0xbdd66b6b, 0xb1de6f6f, 0x5491c5c5, + u32(0xa5c66363), 0x84f87c7c, 0x99ee7777, 0x8df67b7b, 0x0dfff2f2, 0xbdd66b6b, 0xb1de6f6f, 0x5491c5c5, 0x50603030, 0x03020101, 0xa9ce6767, 0x7d562b2b, 0x19e7fefe, 0x62b5d7d7, 0xe64dabab, 0x9aec7676, 0x458fcaca, 0x9d1f8282, 0x4089c9c9, 0x87fa7d7d, 0x15effafa, 0xebb25959, 0xc98e4747, 0x0bfbf0f0, 0xec41adad, 0x67b3d4d4, 0xfd5fa2a2, 0xea45afaf, 0xbf239c9c, 0xf753a4a4, 0x96e47272, 0x5b9bc0c0, @@ -164,7 +164,7 @@ const ( 0xc3824141, 0xb0299999, 0x775a2d2d, 0x111e0f0f, 0xcb7bb0b0, 0xfca85454, 0xd66dbbbb, 0x3a2c1616, ] te2 = [ - 0x63a5c663, 0x7c84f87c, 0x7799ee77, 0x7b8df67b, 0xf20dfff2, 0x6bbdd66b, 0x6fb1de6f, 0xc55491c5, + u32(0x63a5c663), 0x7c84f87c, 0x7799ee77, 0x7b8df67b, 0xf20dfff2, 0x6bbdd66b, 0x6fb1de6f, 0xc55491c5, 0x30506030, 0x01030201, 0x67a9ce67, 0x2b7d562b, 0xfe19e7fe, 0xd762b5d7, 0xabe64dab, 0x769aec76, 0xca458fca, 0x829d1f82, 0xc94089c9, 0x7d87fa7d, 0xfa15effa, 0x59ebb259, 0x47c98e47, 0xf00bfbf0, 0xadec41ad, 0xd467b3d4, 0xa2fd5fa2, 0xafea45af, 0x9cbf239c, 0xa4f753a4, 0x7296e472, 0xc05b9bc0, @@ -198,7 +198,7 @@ const ( 0x41c38241, 0x99b02999, 0x2d775a2d, 0x0f111e0f, 0xb0cb7bb0, 0x54fca854, 0xbbd66dbb, 0x163a2c16, ] te3 = [ - 0x6363a5c6, 0x7c7c84f8, 0x777799ee, 0x7b7b8df6, 0xf2f20dff, 0x6b6bbdd6, 0x6f6fb1de, 0xc5c55491, + u32(0x6363a5c6), 0x7c7c84f8, 0x777799ee, 0x7b7b8df6, 0xf2f20dff, 0x6b6bbdd6, 0x6f6fb1de, 0xc5c55491, 0x30305060, 0x01010302, 0x6767a9ce, 0x2b2b7d56, 0xfefe19e7, 0xd7d762b5, 0xababe64d, 0x76769aec, 0xcaca458f, 0x82829d1f, 0xc9c94089, 0x7d7d87fa, 0xfafa15ef, 0x5959ebb2, 0x4747c98e, 0xf0f00bfb, 0xadadec41, 0xd4d467b3, 0xa2a2fd5f, 0xafafea45, 0x9c9cbf23, 0xa4a4f753, 0x727296e4, 0xc0c05b9b, @@ -236,7 +236,7 @@ const ( // Lookup tables for decryption. const ( td0 = [ - 0x51f4a750, 0x7e416553, 0x1a17a4c3, 0x3a275e96, 0x3bab6bcb, 0x1f9d45f1, 0xacfa58ab, 0x4be30393, + u32(0x51f4a750), 0x7e416553, 0x1a17a4c3, 0x3a275e96, 0x3bab6bcb, 0x1f9d45f1, 0xacfa58ab, 0x4be30393, 0x2030fa55, 0xad766df6, 0x88cc7691, 0xf5024c25, 0x4fe5d7fc, 0xc52acbd7, 0x26354480, 0xb562a38f, 0xdeb15a49, 0x25ba1b67, 0x45ea0e98, 0x5dfec0e1, 0xc32f7502, 0x814cf012, 0x8d4697a3, 0x6bd3f9c6, 0x038f5fe7, 0x15929c95, 0xbf6d7aeb, 0x955259da, 0xd4be832d, 0x587421d3, 0x49e06929, 0x8ec9c844, @@ -270,7 +270,7 @@ const ( 0x39a80171, 0x080cb3de, 0xd8b4e49c, 0x6456c190, 0x7bcb8461, 0xd532b670, 0x486c5c74, 0xd0b85742, ] td1 = [ - 0x5051f4a7, 0x537e4165, 0xc31a17a4, 0x963a275e, 0xcb3bab6b, 0xf11f9d45, 0xabacfa58, 0x934be303, + u32(0x5051f4a7), 0x537e4165, 0xc31a17a4, 0x963a275e, 0xcb3bab6b, 0xf11f9d45, 0xabacfa58, 0x934be303, 0x552030fa, 0xf6ad766d, 0x9188cc76, 0x25f5024c, 0xfc4fe5d7, 0xd7c52acb, 0x80263544, 0x8fb562a3, 0x49deb15a, 0x6725ba1b, 0x9845ea0e, 0xe15dfec0, 0x02c32f75, 0x12814cf0, 0xa38d4697, 0xc66bd3f9, 0xe7038f5f, 0x9515929c, 0xebbf6d7a, 0xda955259, 0x2dd4be83, 0xd3587421, 0x2949e069, 0x448ec9c8, @@ -304,7 +304,7 @@ const ( 0x7139a801, 0xde080cb3, 0x9cd8b4e4, 0x906456c1, 0x617bcb84, 0x70d532b6, 0x74486c5c, 0x42d0b857, ] td2 = [ - 0xa75051f4, 0x65537e41, 0xa4c31a17, 0x5e963a27, 0x6bcb3bab, 0x45f11f9d, 0x58abacfa, 0x03934be3, + u32(0xa75051f4), 0x65537e41, 0xa4c31a17, 0x5e963a27, 0x6bcb3bab, 0x45f11f9d, 0x58abacfa, 0x03934be3, 0xfa552030, 0x6df6ad76, 0x769188cc, 0x4c25f502, 0xd7fc4fe5, 0xcbd7c52a, 0x44802635, 0xa38fb562, 0x5a49deb1, 0x1b6725ba, 0x0e9845ea, 0xc0e15dfe, 0x7502c32f, 0xf012814c, 0x97a38d46, 0xf9c66bd3, 0x5fe7038f, 0x9c951592, 0x7aebbf6d, 0x59da9552, 0x832dd4be, 0x21d35874, 0x692949e0, 0xc8448ec9, @@ -338,7 +338,7 @@ const ( 0x017139a8, 0xb3de080c, 0xe49cd8b4, 0xc1906456, 0x84617bcb, 0xb670d532, 0x5c74486c, 0x5742d0b8, ] td3 = [ - 0xf4a75051, 0x4165537e, 0x17a4c31a, 0x275e963a, 0xab6bcb3b, 0x9d45f11f, 0xfa58abac, 0xe303934b, + u32(0xf4a75051), 0x4165537e, 0x17a4c31a, 0x275e963a, 0xab6bcb3b, 0x9d45f11f, 0xfa58abac, 0xe303934b, 0x30fa5520, 0x766df6ad, 0xcc769188, 0x024c25f5, 0xe5d7fc4f, 0x2acbd7c5, 0x35448026, 0x62a38fb5, 0xb15a49de, 0xba1b6725, 0xea0e9845, 0xfec0e15d, 0x2f7502c3, 0x4cf01281, 0x4697a38d, 0xd3f9c66b, 0x8f5fe703, 0x929c9515, 0x6d7aebbf, 0x5259da95, 0xbe832dd4, 0x7421d358, 0xe0692949, 0xc9c8448e, diff --git a/vlib/crypto/md5/md5.v b/vlib/crypto/md5/md5.v index c7e003d6f3..396d012cab 100644 --- a/vlib/crypto/md5/md5.v +++ b/vlib/crypto/md5/md5.v @@ -107,8 +107,8 @@ pub fn (mut d Digest) checksum() []byte { // tmp := [1 + 63 + 8]byte{0x80} mut tmp := [byte(0)].repeat(1 + 63 + 8) tmp[0] = 0x80 - pad := ((55 - int(d.len)) % u64(64)) // calculate number of padding bytes - binary.little_endian_put_u64(mut tmp[1+pad..], d.len<> 16 - b[j+1] = (decoded_bytes >> 8) & 0xff - b[j+2] = (decoded_bytes >> 0) & 0xff + b[j] = byte(decoded_bytes >> 16) + b[j+1] = byte((decoded_bytes >> 8) & 0xff) + b[j+2] = byte((decoded_bytes >> 0) & 0xff) j += 3 } return output_length diff --git a/vlib/encoding/base64/base64_memory_test.v b/vlib/encoding/base64/base64_memory_test.v index 161eee8c9d..99828a36cb 100644 --- a/vlib/encoding/base64/base64_memory_test.v +++ b/vlib/encoding/base64/base64_memory_test.v @@ -14,14 +14,14 @@ fn test_long_encoding(){ mut s := 0 ebuffer := malloc( s_encoded.len ) - for i in 0..repeats { + for _ in 0..repeats { resultsize := base64.encode_in_buffer(s_original, ebuffer) s += resultsize assert resultsize == s_encoded.len } dbuffer := malloc( s_decoded.len ) - for i in 0..repeats { + for _ in 0..repeats { resultsize := base64.decode_in_buffer(s_encoded, dbuffer) s += resultsize assert resultsize == s_decoded.len diff --git a/vlib/encoding/utf8/utf8_util.v b/vlib/encoding/utf8/utf8_util.v index 14d1dab3dc..fc3522d1fa 100644 --- a/vlib/encoding/utf8/utf8_util.v +++ b/vlib/encoding/utf8/utf8_util.v @@ -172,9 +172,9 @@ fn up_low(s string, upper_flag bool) string { if ch_len == 1 { if upper_flag==true { - str_res[index] = C.toupper(s.str[index]) + str_res[index] = byte(C.toupper(s.str[index])) }else{ - str_res[index] = C.tolower(s.str[index]) + str_res[index] = byte(C.tolower(s.str[index])) } } else if ch_len > 1 && ch_len < 5{ diff --git a/vlib/glm/glm.v b/vlib/glm/glm.v index 59a67f47f2..9db44dbdf1 100644 --- a/vlib/glm/glm.v +++ b/vlib/glm/glm.v @@ -77,8 +77,8 @@ pub fn (m Mat4) str() string { fn vec2(x, y int) Vec2 { res := Vec2 { - x: x, - y: y, + x: f32(x), + y: f32(y), } return res } @@ -131,7 +131,7 @@ fn rotate(m Mat4, angle f32, vec Vec3) Mat4 { */ fn f32_calloc(n int) &f32 { - return &f32(vcalloc(n * sizeof(f32))) + return voidptr(vcalloc(n * int(sizeof(f32)))) } // fn translate(vec Vec3) *f32 { pub fn translate(m Mat4, v Vec3) Mat4 { @@ -273,9 +273,9 @@ fn mult_mat_point(a Mat4, point Mat4) Mat4 { } pub fn rotate(angle f32, axis Vec3, src Mat4) Mat4 { - c := math.cos(angle) - s := math.sin(angle) - oneminusc := 1.0 - c + c := f32(math.cos(angle)) + s := f32(math.sin(angle)) + oneminusc := f32(1.0) - c xy := axis.x * axis.y yz := axis.y * axis.z @@ -325,8 +325,8 @@ pub fn rotate(angle f32, axis Vec3, src Mat4) Mat4 { pub fn rotate_z(m Mat4, rad f32) Mat4 { a := m.data mut out := f32_calloc(16) - s := math.sin(rad) - c := math.cos(rad) + s := f32(math.sin(rad)) + c := f32(math.cos(rad)) a00 := a[0] a01 := a[1] a02 := a[2] @@ -361,7 +361,7 @@ pub fn identity() Mat4 { // 0 0 1 0 // 0 0 0 1 n := 16 - mut res := f32_calloc(sizeof(f32) * n) + mut res := f32_calloc(int(sizeof(f32)) * n) res[0] = 1 res[5] = 1 res[10] = 1 @@ -396,7 +396,7 @@ fn ortho_js(left, right, bottom, top f32) &f32 { // myfar := 1 lr := 1.0 / (left - right) bt := 1.0 / (bottom - top) - nf := 1.0 / 1.0// (mynear -myfar) + nf := f32(1.0) / 1.0// (mynear -myfar) mut out := &f32(0) unsafe { out = &f32( malloc (sizeof(f32) * 16)) } out[0] = -2.0 * lr diff --git a/vlib/math/bits/bits_test.v b/vlib/math/bits/bits_test.v index dfd35f1d0c..b2f809fe34 100644 --- a/vlib/math/bits/bits_test.v +++ b/vlib/math/bits/bits_test.v @@ -89,12 +89,12 @@ fn test_bits(){ // 8 bit i = 0 - for x in 0..9 { + for _ in 0..9 { mut rv := byte(0) mut bc := 0 mut n := i for bc < 8 { - rv = (rv << 1) | (n & 0x01) + rv = (rv << 1) | (byte(n) & 0x01) bc++ n = n >> 1 } @@ -105,12 +105,12 @@ fn test_bits(){ // 16 bit i = 0 - for x in 0..17 { + for _ in 0..17 { mut rv := u16(0) mut bc := 0 mut n := i for bc < 16 { - rv = (rv << 1) | (n & 0x01) + rv = (rv << 1) | (u16(n) & 0x01) bc++ n = n >> 1 } @@ -121,12 +121,12 @@ fn test_bits(){ // 32 bit i = 0 - for x in 0..33 { + for _ in 0..33 { mut rv := u32(0) mut bc := 0 mut n := i for bc < 32 { - rv = (rv << 1) | (n & 0x01) + rv = (rv << 1) | (u32(n) & 0x01) bc++ n = n >> 1 } @@ -137,7 +137,7 @@ fn test_bits(){ // 64 bit i1 = 0 - for x in 0..64 { + for _ in 0..64 { mut rv := u64(0) mut bc := 0 mut n := i1 diff --git a/vlib/math/fractions/approximations.v b/vlib/math/fractions/approximations.v index bd325774f0..3d8e2f97e8 100644 --- a/vlib/math/fractions/approximations.v +++ b/vlib/math/fractions/approximations.v @@ -56,7 +56,7 @@ fn eval_cf(whole i64, den []i64) Fraction { } else { last := count - 1 - mut n := 1 + mut n := i64(1) mut d := den[last] // The calculations are done from back to front for index := count - 2; index >= 0; index-- { @@ -90,7 +90,7 @@ pub fn approximate_with_eps(val, eps f64) Fraction { // The integer part is separated first. Then we process the fractional // part to generate numerators and denominators in tandem. whole := i64(val) - mut frac := val - whole + mut frac := val - f64(whole) // Quick exit for integers if frac == 0.0 { return fraction(whole, 1) @@ -113,7 +113,7 @@ pub fn approximate_with_eps(val, eps f64) Fraction { if math.fabs(val - partial.f64()) < eps { return partial } - frac -= den + frac -= f64(den) } panic("Couldn\'t converge. Please create an issue on https://github.com/vlang/v") } diff --git a/vlib/math/math_test.v b/vlib/math/math_test.v index f869326ea7..1fe5206892 100644 --- a/vlib/math/math_test.v +++ b/vlib/math/math_test.v @@ -56,7 +56,7 @@ fn test_gamma() { fn test_mod() { assert 4 % 2 == 0 - x := 2 + x := u64(2) assert u64(5) % x == 1 mut a := 10 a %= 2 diff --git a/vlib/regex/regex.v b/vlib/regex/regex.v index 90896e06bb..3bc9eb832b 100644 --- a/vlib/regex/regex.v +++ b/vlib/regex/regex.v @@ -1149,7 +1149,7 @@ pub fn (mut re RE) compile(in_txt string) (int,int) { // ist_simple_char re.prog[pc].ist = ist_simple_char re.prog[pc].ch = char_tmp - re.prog[pc].ch_len = char_len + re.prog[pc].ch_len = byte(char_len) re.prog[pc].rep_min = 1 re.prog[pc].rep_max = 1 //println("char: ${char_tmp:c}") diff --git a/vlib/regex/regex_test.v b/vlib/regex/regex_test.v index ee04ff70da..a14028a143 100644 --- a/vlib/regex/regex_test.v +++ b/vlib/regex/regex_test.v @@ -152,19 +152,19 @@ cgroups_test_suite = [ "http://www.ciao.mondo/hello/pippo12_/pera.html", r"(?Phttps?)|(?:ftps?)://(?P[\w_]+.)+",0,46, [8, 0, 0, 4, 1, 7, 11, 1, 11, 16, 1, 16, 22, 1, 22, 28, 1, 28, 37, 1, 37, 42, 1, 42, 46], - {'format':0,'token':1} + {'format':int(0),'token':1} }, TestItemCGroup{ "http://www.ciao.mondo/hello/pippo12_/pera.html", r"(?Phttps?)|(?Pftps?)://(?P[\w_]+.)+",0,46, [8, 0, 0, 4, 1, 7, 11, 1, 11, 16, 1, 16, 22, 1, 22, 28, 1, 28, 37, 1, 37, 42, 1, 42, 46], - {'format':0,'token':1} + {'format':int(0),'token':1} }, TestItemCGroup{ "http://www.ciao.mondo/hello/pippo12_/pera.html", r"(?Phttps?)|(?Pftps?)://([\w_]+.)+",0,46, [8, 0, 0, 4, 1, 7, 11, 1, 11, 16, 1, 16, 22, 1, 22, 28, 1, 28, 37, 1, 37, 42, 1, 42, 46], - {'format':0} + {'format':int(0)} }, ] ) diff --git a/vlib/time/time_test.v b/vlib/time/time_test.v index ca9b7e4153..1e6f789682 100644 --- a/vlib/time/time_test.v +++ b/vlib/time/time_test.v @@ -143,7 +143,7 @@ fn test_add_days() { num_of_days := 3 t := time_to_test.add_days(num_of_days) assert t.day == time_to_test.day + num_of_days - assert t.unix == time_to_test.unix + 86400 * num_of_days + assert t.unix == time_to_test.unix + 86400 * u64(num_of_days) } fn test_str() { diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 05b98c3a1d..c971195492 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2636,7 +2636,7 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) { if fspec == `_` { // set default representation for type if still missing if node.expr_types[i].is_float() { fspec = `g` - } else if node.expr_types[i].is_signed() { + } else if node.expr_types[i].is_signed() || node.expr_types[i].is_any_int() { fspec = `d` } else if node.expr_types[i].is_unsigned() { fspec = `u` @@ -2658,7 +2658,7 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) { fields.len == 2 && !(node.expr_types[i].is_float()) || node.expr_types[i].is_signed() && fspec !in [`d`, `c`, `x`, `X`, `o`] || node.expr_types[i].is_unsigned() && fspec !in [`u`, `x`, `X`, `o`, `c`] || - node.expr_types[i].is_any_int() && fspec !in [`d`, `c`, `x`, `X`, `o`, `u`, `x`, `X`, `o`, `c`] || + node.expr_types[i].is_any_int() && fspec !in [`d`, `c`, `x`, `X`, `o`, `u`, `x`, `X`, `o`] || node.expr_types[i].is_float() && fspec !in [`E`, `F`, `G`, `e`, `f`, `g`] || node.expr_types[i].is_pointer() && fspec !in [`p`, `x`, `X`] { verror('illegal format specifier ${fspec:c} for type ${g.table.get_type_name(node.expr_types[i])}') diff --git a/vlib/v/tests/complex_assign_test.v b/vlib/v/tests/complex_assign_test.v index 90de5981f8..8fa4e1c96e 100644 --- a/vlib/v/tests/complex_assign_test.v +++ b/vlib/v/tests/complex_assign_test.v @@ -57,7 +57,7 @@ fn test_assign_multi_expr() { g, h, i := if true { 1 + val1, awesome, [13] } else { - 0, 'bad', [0] + int(0), 'bad', [0] } assert g == 2 assert h == 'awesome' diff --git a/vlib/v/tests/map_to_string_test.v b/vlib/v/tests/map_to_string_test.v index 760beced80..7617ce74ab 100644 --- a/vlib/v/tests/map_to_string_test.v +++ b/vlib/v/tests/map_to_string_test.v @@ -23,6 +23,7 @@ fn test_interpolation_map_to_string() { assert '$c' == "{'1': true, '2': false}" d := {'f1': 1.1, 'f2': 2.2, 'f3': 3.3, 'f4': 4.4} + println('d: $d') assert '$d' == "{'f1': 1.1, 'f2': 2.2, 'f3': 3.3, 'f4': 4.4}" mut e := map[string]Test diff --git a/vlib/v/tests/match_expression_for_types_test.v b/vlib/v/tests/match_expression_for_types_test.v index e3aca2ec34..a2b282f1a0 100644 --- a/vlib/v/tests/match_expression_for_types_test.v +++ b/vlib/v/tests/match_expression_for_types_test.v @@ -26,7 +26,7 @@ fn test_match_expression_on_sumtype_else(){ // tests whether else branches support multiple statements, // when the other branches are simple default expressions mut c := 0 - s := s2s(123) + s := s2s(int(123)) res := match s { string { 'a string' @@ -44,7 +44,7 @@ fn test_match_expression_on_sumtype_full(){ // tests whether all branches can have multiple statements, // followed by a default expression mut c := 0 - s := s2s(123) + s := s2s(int(123)) res := match s { int { c = 1 diff --git a/vlib/v/tests/shift_test.v b/vlib/v/tests/shift_test.v index 04aa4741ed..597e8389a0 100644 --- a/vlib/v/tests/shift_test.v +++ b/vlib/v/tests/shift_test.v @@ -41,10 +41,11 @@ fn test_shift_operators() { assert e == b e >>= int(i) assert e == a - e <<= i64(i) - assert e == b - e >>= i64(i) - assert e == a + mut e2 := i64(1) + e2 <<= i64(i) + assert e2 == b + e2 >>= i64(i) + assert e2 == a e <<= byte(i) assert e == b e >>= byte(i) @@ -53,12 +54,13 @@ fn test_shift_operators() { assert e == b e >>= u16(i) assert e == a - e <<= u32(i) - assert e == b - e >>= u32(i) - assert e == a - e <<= u64(i) - assert e == b - e >>= u64(i) + mut e3 := u64(1) + e3 <<= u32(i) + assert e3 == b + e3 >>= u32(i) assert e == a + e3 <<= u64(i) + assert e3 == b + e3 >>= u64(i) + assert e3 == a } diff --git a/vlib/v/tests/string_interpolation_array_test.v b/vlib/v/tests/string_interpolation_array_test.v index 25406a99e8..f60661c038 100644 --- a/vlib/v/tests/string_interpolation_array_test.v +++ b/vlib/v/tests/string_interpolation_array_test.v @@ -79,7 +79,7 @@ fn test_array_of_strings_interpolation() { fn test_array_of_map_interpolation() { mut a := []map[string]int{} - a << {'a': 1, 'b': 2} - a << {'c': 3, 'd': 4} + a << {'a': int(1), 'b': 2} + a << {'c': int(3), 'd': 4} assert '$a' == "[{'a': 1, 'b': 2}, {'c': 3, 'd': 4}]" } diff --git a/vlib/v/tests/string_interpolation_struct_test.v b/vlib/v/tests/string_interpolation_struct_test.v index 5ba4a5a29d..eb933a196e 100644 --- a/vlib/v/tests/string_interpolation_struct_test.v +++ b/vlib/v/tests/string_interpolation_struct_test.v @@ -42,7 +42,7 @@ struct Info { fn test_struct_map_field_string_interpolation() { info := Info{ name: 'test' - dict: {'a': 1, 'b': 2} + dict: {'a': int(1), 'b': 2} } s := '$info' assert s.starts_with('Info {') diff --git a/vlib/v/tests/typeof_simple_types_test.v b/vlib/v/tests/typeof_simple_types_test.v index 8b06d8390b..c79474467f 100644 --- a/vlib/v/tests/typeof_simple_types_test.v +++ b/vlib/v/tests/typeof_simple_types_test.v @@ -19,7 +19,8 @@ type SuperSumType = MySumType | AnotherSumType | string fn test_typeof_for_builtin_int_types() { assert typeof(i8(1)) == 'i8' assert typeof(i16(1)) == 'i16' - assert typeof(1) == 'int' + assert typeof(int(1)) == 'int' + // assert typeof(1) == 'any_int' assert typeof(i64(1)) == 'i64' assert typeof(byte(1)) == 'byte' assert typeof(u16(1)) == 'u16' @@ -29,7 +30,8 @@ fn test_typeof_for_builtin_int_types() { fn test_typeof_for_builtin_float_types() { assert typeof(f32(1.0)) == 'f32' - assert typeof(1.0) == 'f64' + assert typeof(f64(1.0)) == 'f64' + // assert typeof(1.0) == 'any_float' } fn test_typeof_for_builtin_string_type() { diff --git a/vlib/v/tests/typeof_test.v b/vlib/v/tests/typeof_test.v index 347568950d..6a1b3a76c3 100644 --- a/vlib/v/tests/typeof_test.v +++ b/vlib/v/tests/typeof_test.v @@ -1,10 +1,17 @@ fn test_typeof_on_simple_expressions() { - a := 123 - assert typeof(42) == 'int' - assert typeof(3.14) == 'f64' - assert typeof(2+2*10) == 'int' - assert typeof(1.0 * 12.2) == 'f64' + a := int(123) + assert typeof(int(42)) == 'int' + assert typeof(f64(3.14)) == 'f64' + assert typeof(int(2)+2*10) == 'int' + assert typeof(f64(1.0) * 12.2) == 'f64' + // assert typeof(1.0 * f32(12.2)) == 'f32' assert typeof(a) == 'int' + // a2 := 123 + // assert typeof(a2) == 'any_int' + // assert typeof(42) == 'any_int' + // assert typeof(3.14) == 'any_float' + // assert typeof(2+2*10) == 'any_int' + // assert typeof(1.0 * 12.2) == 'any_float' } fn test_typeof_on_atypes() { @@ -38,7 +45,7 @@ pub fn (ms MySumType) str() string { } fn test_typeof_on_sumtypes() { - a := MySumType(32) + a := MySumType(int(32)) b := MySumType(f32(123.0)) c := MySumType(FooBar{x:43}) assert typeof(a) == 'int' diff --git a/vlib/vweb/assets/assets.v b/vlib/vweb/assets/assets.v index 6de738bbe3..b0ce10f944 100644 --- a/vlib/vweb/assets/assets.v +++ b/vlib/vweb/assets/assets.v @@ -113,7 +113,7 @@ fn (am AssetManager) combine(asset_type string, to_file bool) string { fn (am AssetManager) get_cache_key(asset_type string) string { mut files_salt := '' - mut latest_modified := 0 + mut latest_modified := u64(0) for asset in am.get_assets(asset_type) { files_salt += asset.file_path if asset.last_modified.unix > latest_modified { @@ -157,7 +157,7 @@ fn (mut am AssetManager) add(asset_type, file string) bool { } asset := Asset{ file_path: file - last_modified: time.Time{unix: os.file_last_mod_unix(file)} + last_modified: time.Time{unix: u64(os.file_last_mod_unix(file))} } if asset_type == 'css' { am.css << asset