mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
checker: warn about byte deprecation, when used as a fn parameter (#19629)
This commit is contained in:
parent
8a8129cd5c
commit
6437d82ee1
9 changed files with 20 additions and 10 deletions
|
@ -3,7 +3,7 @@ module builtin
|
||||||
// vstrlen returns the V length of the C string `s` (0 terminator is not counted).
|
// 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.
|
// The C string is expected to be a &byte pointer.
|
||||||
[inline; unsafe]
|
[inline; unsafe]
|
||||||
pub fn vstrlen(s &byte) int {
|
pub fn vstrlen(s &u8) int {
|
||||||
return unsafe { C.strlen(&char(s)) }
|
return unsafe { C.strlen(&char(s)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ pub fn (x StrIntpType) str() string {
|
||||||
pub union StrIntpMem {
|
pub union StrIntpMem {
|
||||||
pub mut:
|
pub mut:
|
||||||
d_c u32
|
d_c u32
|
||||||
d_u8 byte
|
d_u8 u8
|
||||||
d_i8 i8
|
d_i8 i8
|
||||||
d_u16 u16
|
d_u16 u16
|
||||||
d_i16 i16
|
d_i16 i16
|
||||||
|
@ -114,7 +114,7 @@ fn abs64(x i64) u64 {
|
||||||
//---------------------------------------
|
//---------------------------------------
|
||||||
|
|
||||||
// convert from data format to compact 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) }
|
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
|
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) }
|
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
|
// 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) }
|
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
|
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) }
|
upper_case := if in_upper_case { u32(1 << 7) } else { u32(0) }
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module subtle
|
module subtle
|
||||||
|
|
||||||
// constant_time_byte_eq returns 1 when x == y.
|
// 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)
|
return int((u32(x ^ y) - 1) >> 31)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ pub fn (mut stmt Stmt) bind_bool(b &bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// bind_byte binds a single byte value to the statement `stmt`
|
// 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)
|
stmt.bind(mysql.mysql_type_tiny, b, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,8 +194,8 @@ fn encode_i64(val i64) &C.cJSON {
|
||||||
|
|
||||||
// TODO: remove when `byte` is removed
|
// TODO: remove when `byte` is removed
|
||||||
[markused]
|
[markused]
|
||||||
fn encode_byte(root byte) &C.cJSON {
|
fn encode_byte(root u8) &C.cJSON {
|
||||||
return encode_u8(u8(root))
|
return encode_u8(root)
|
||||||
}
|
}
|
||||||
|
|
||||||
[markused]
|
[markused]
|
||||||
|
|
|
@ -70,7 +70,7 @@ pub fn (mut b Builder) write_u8(data u8) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// write_byte appends a single `data` byte to the accumulated buffer
|
// 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
|
b << data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub fn new_builder(initial_size int) Builder {
|
||||||
return []u8{cap: initial_size}
|
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
|
b << data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -271,6 +271,9 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
|
||||||
if c.check_import_sym_conflict(param.name) {
|
if c.check_import_sym_conflict(param.name) {
|
||||||
c.error('duplicate of an import symbol `${param.name}`', param.pos)
|
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 {
|
if !node.is_method {
|
||||||
// Check if function name is already registered as imported module symbol
|
// Check if function name is already registered as imported module symbol
|
||||||
|
|
|
@ -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
|
vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv:3:1: error: top level declaration cannot shadow builtin type
|
||||||
1 |
|
1 |
|
||||||
2 | [inline]
|
2 | [inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue