checker: warn about byte deprecation, when used as a fn parameter (#19629)

This commit is contained in:
Turiiya 2023-10-23 19:54:28 +02:00 committed by GitHub
parent 8a8129cd5c
commit 6437d82ee1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 10 deletions

View file

@ -3,7 +3,7 @@ module builtin
// vstrlen returns the V length of the C string `s` (0 terminator is not counted).
// The C string is expected to be a &byte pointer.
[inline; unsafe]
pub fn vstrlen(s &byte) int {
pub fn vstrlen(s &u8) int {
return unsafe { C.strlen(&char(s)) }
}

View file

@ -64,7 +64,7 @@ pub fn (x StrIntpType) str() string {
pub union StrIntpMem {
pub mut:
d_c u32
d_u8 byte
d_u8 u8
d_i8 i8
d_u16 u16
d_i16 i16
@ -114,7 +114,7 @@ fn abs64(x i64) u64 {
//---------------------------------------
// convert from data format to compact u64
pub fn get_str_intp_u64_format(fmt_type StrIntpType, in_width int, in_precision int, in_tail_zeros bool, in_sign bool, in_pad_ch byte, in_base int, in_upper_case bool) u64 {
pub fn get_str_intp_u64_format(fmt_type StrIntpType, in_width int, in_precision int, in_tail_zeros bool, in_sign bool, in_pad_ch u8, in_base int, in_upper_case bool) u64 {
width := if in_width != 0 { abs64(in_width) } else { u64(0) }
allign := if in_width > 0 { u64(1 << 5) } else { u64(0) } // two bit 0 .left 1 .rigth, for now we use only one
upper_case := if in_upper_case { u64(1 << 7) } else { u64(0) }
@ -131,7 +131,7 @@ pub fn get_str_intp_u64_format(fmt_type StrIntpType, in_width int, in_precision
}
// convert from data format to compact u32
pub fn get_str_intp_u32_format(fmt_type StrIntpType, in_width int, in_precision int, in_tail_zeros bool, in_sign bool, in_pad_ch byte, in_base int, in_upper_case bool) u32 {
pub fn get_str_intp_u32_format(fmt_type StrIntpType, in_width int, in_precision int, in_tail_zeros bool, in_sign bool, in_pad_ch u8, in_base int, in_upper_case bool) u32 {
width := if in_width != 0 { abs64(in_width) } else { u32(0) }
allign := if in_width > 0 { u32(1 << 5) } else { u32(0) } // two bit 0 .left 1 .rigth, for now we use only one
upper_case := if in_upper_case { u32(1 << 7) } else { u32(0) }

View file

@ -1,7 +1,7 @@
module subtle
// constant_time_byte_eq returns 1 when x == y.
pub fn constant_time_byte_eq(x byte, y byte) int {
pub fn constant_time_byte_eq(x u8, y u8) int {
return int((u32(x ^ y) - 1) >> 31)
}

View file

@ -188,7 +188,7 @@ pub fn (mut stmt Stmt) bind_bool(b &bool) {
}
// bind_byte binds a single byte value to the statement `stmt`
pub fn (mut stmt Stmt) bind_byte(b &byte) {
pub fn (mut stmt Stmt) bind_byte(b &u8) {
stmt.bind(mysql.mysql_type_tiny, b, 0)
}

View file

@ -194,8 +194,8 @@ fn encode_i64(val i64) &C.cJSON {
// TODO: remove when `byte` is removed
[markused]
fn encode_byte(root byte) &C.cJSON {
return encode_u8(u8(root))
fn encode_byte(root u8) &C.cJSON {
return encode_u8(root)
}
[markused]

View file

@ -70,7 +70,7 @@ pub fn (mut b Builder) write_u8(data u8) {
}
// write_byte appends a single `data` byte to the accumulated buffer
pub fn (mut b Builder) write_byte(data byte) {
pub fn (mut b Builder) write_byte(data u8) {
b << data
}

View file

@ -18,7 +18,7 @@ pub fn new_builder(initial_size int) Builder {
return []u8{cap: initial_size}
}
pub fn (mut b Builder) write_byte(data byte) {
pub fn (mut b Builder) write_byte(data u8) {
b << data
}

View file

@ -271,6 +271,9 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
if c.check_import_sym_conflict(param.name) {
c.error('duplicate of an import symbol `${param.name}`', param.pos)
}
if arg_typ_sym.kind == .alias && arg_typ_sym.name == 'byte' {
c.warn('byte is deprecated, use u8 instead', param.type_pos)
}
}
if !node.is_method {
// Check if function name is already registered as imported module symbol

View file

@ -1,3 +1,10 @@
vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv:3:12: warning: byte is deprecated, use u8 instead
1 |
2 | [inline]
3 | fn char(ch byte) fn (string) !(byte, string) {
| ~~~~
4 | return fn [ch] (input string) !(byte, string) {
5 | return if input[0] == ch {
vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv:3:1: error: top level declaration cannot shadow builtin type
1 |
2 | [inline]