Skip to content

Commit

Permalink
checker: extend byte deprecation warnings to return types (#19668)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Oct 29, 2023
1 parent e86abe0 commit 1e578b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 2 additions & 4 deletions vlib/builtin/string.v
Expand Up @@ -1735,15 +1735,13 @@ pub fn (s string) str() string {

// at returns the byte at index `idx`.
// Example: assert 'ABC'.at(1) == u8(`B`)
fn (s string) at(idx int) byte {
fn (s string) at(idx int) u8 {
$if !no_bounds_checking {
if idx < 0 || idx >= s.len {
panic('string index out of range: ${idx} / ${s.len}')
}
}
unsafe {
return s.str[idx]
}
return unsafe { s.str[idx] }
}

// version of `at()` that is used in `a[i] or {`
Expand Down
4 changes: 2 additions & 2 deletions vlib/json/json_primitives.v
Expand Up @@ -86,8 +86,8 @@ fn decode_i64(root &C.cJSON) i64 {

// TODO: remove when `byte` is removed
[markused]
fn decode_byte(root &C.cJSON) byte {
return byte(decode_u8(root))
fn decode_byte(root &C.cJSON) u8 {
return decode_u8(root)
}

[markused]
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/checker/fn.v
Expand Up @@ -126,6 +126,9 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
c.table.find_or_register_array_fixed(parent_sym.info.elem_type, parent_sym.info.size,
parent_sym.info.size_expr, true)
}
if return_sym.name == 'byte' {
c.warn('byte is deprecated, use u8 instead', node.return_type_pos)
}
}
final_return_sym := c.table.final_sym(node.return_type)
if final_return_sym.info is ast.MultiReturn {
Expand Down

0 comments on commit 1e578b1

Please sign in to comment.