diff --git a/vlib/v/checker/assign.v b/vlib/v/checker/assign.v index 1dbd32b06c9b58..23aaf67e4d6b43 100644 --- a/vlib/v/checker/assign.v +++ b/vlib/v/checker/assign.v @@ -870,7 +870,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.', c.error('cannot assign anonymous `struct` to a typed `struct`', right.pos()) } if right_sym.kind == .alias && right_sym.name == 'byte' { - c.warn('byte is deprecated, use u8 instead', right.pos()) + c.error('byte is deprecated, use u8 instead', right.pos()) } } // this needs to run after the assign stmt left exprs have been run through checker diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index ffc4eb2af38a02..9c55958fc19bac 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -36,7 +36,7 @@ pub const fixed_array_builtin_methods = ['contains', 'index', 'any', 'all', 'wai 'sorted', 'sort_with_compare', 'sorted_with_compare', 'reverse', 'reverse_in_place', 'count'] pub const fixed_array_builtin_methods_chk = token.new_keywords_matcher_from_array_trie(fixed_array_builtin_methods) // TODO: remove `byte` from this list when it is no longer supported -pub const reserved_type_names = ['byte', 'bool', 'char', 'i8', 'i16', 'int', 'i64', 'u8', 'u16', +pub const reserved_type_names = ['bool', 'char', 'i8', 'i16', 'int', 'i64', 'u8', 'u16', 'u32', 'u64', 'f32', 'f64', 'map', 'string', 'rune', 'usize', 'isize', 'voidptr', 'thread'] pub const reserved_type_names_chk = token.new_keywords_matcher_from_array_trie(reserved_type_names) pub const vroot_is_deprecated_message = '@VROOT is deprecated, use @VMODROOT or @VEXEROOT instead' diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index dd50fca57274d0..2de7d37d3f70e7 100644 --- a/vlib/v/checker/containers.v +++ b/vlib/v/checker/containers.v @@ -61,7 +61,7 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type { } ast.Alias { if elem_sym.name == 'byte' { - c.warn('byte is deprecated, use u8 instead', node.elem_type_pos) + c.error('byte is deprecated, use u8 instead', node.elem_type_pos) } } ast.Map { diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 44b820d1fafb32..c5d372d1083299 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -167,7 +167,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { parent_sym.info.size_expr, true) } if return_sym.name == 'byte' { - c.warn('byte is deprecated, use u8 instead', node.return_type_pos) + c.error('byte is deprecated, use u8 instead', node.return_type_pos) } } if return_sym.info is ast.ArrayFixed && c.array_fixed_has_unresolved_size(return_sym.info) { @@ -337,7 +337,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { 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) + c.error('byte is deprecated, use u8 instead', param.type_pos) } } if !node.is_method { diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index db720e57feca70..6e4f17d9019f46 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -220,7 +220,7 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) { } .alias { if sym.name == 'byte' { - c.warn('byte is deprecated, use u8 instead', field.type_pos) + c.error('byte is deprecated, use u8 instead', field.type_pos) } } else { diff --git a/vlib/v/checker/tests/dump_char.out b/vlib/v/checker/tests/dump_char.out index 8c93ce4922ed84..a716b35c03a88f 100644 --- a/vlib/v/checker/tests/dump_char.out +++ b/vlib/v/checker/tests/dump_char.out @@ -1,5 +1,5 @@ vlib/v/checker/tests/dump_char.vv:3:6: error: `char` values cannot be dumped directly, use dump(u8(x)) or dump(int(x)) instead 1 | c := char(67) - 2 | dump(byte(c)) + 2 | dump(u8(c)) 3 | dump(c) | ^ diff --git a/vlib/v/checker/tests/dump_char.vv b/vlib/v/checker/tests/dump_char.vv index 84a6354ab5f411..4b127f6244fed1 100644 --- a/vlib/v/checker/tests/dump_char.vv +++ b/vlib/v/checker/tests/dump_char.vv @@ -1,3 +1,3 @@ c := char(67) -dump(byte(c)) +dump(u8(c)) dump(c) diff --git a/vlib/v/checker/tests/struct_type_cast_err.out b/vlib/v/checker/tests/struct_type_cast_err.out index 9f069f89f40c01..d96facf454686d 100644 --- a/vlib/v/checker/tests/struct_type_cast_err.out +++ b/vlib/v/checker/tests/struct_type_cast_err.out @@ -1,10 +1,3 @@ -vlib/v/checker/tests/struct_type_cast_err.vv:10:7: warning: byte is deprecated, use u8 instead - 8 | _ := u32(foo) - 9 | _ := rune(foo) - 10 | _ := byte(foo) - | ~~~~~~~~~ - 11 | _ := i8(foo) - 12 | _ := i64(foo) vlib/v/checker/tests/struct_type_cast_err.vv:5:7: error: cannot cast struct `Foo` to `string` 3 | fn main() { 4 | foo := Foo{} @@ -32,30 +25,30 @@ vlib/v/checker/tests/struct_type_cast_err.vv:8:7: error: cannot cast struct `Foo 8 | _ := u32(foo) | ~~~~~~~~ 9 | _ := rune(foo) - 10 | _ := byte(foo) + 10 | _ := u8(foo) vlib/v/checker/tests/struct_type_cast_err.vv:9:7: error: cannot cast struct `Foo` to `rune` 7 | _ := u64(foo) 8 | _ := u32(foo) 9 | _ := rune(foo) | ~~~~~~~~~ - 10 | _ := byte(foo) + 10 | _ := u8(foo) 11 | _ := i8(foo) -vlib/v/checker/tests/struct_type_cast_err.vv:10:7: error: cannot cast `Foo` to `byte` (alias to `u8`) +vlib/v/checker/tests/struct_type_cast_err.vv:10:7: error: cannot cast struct `Foo` to `u8` 8 | _ := u32(foo) 9 | _ := rune(foo) - 10 | _ := byte(foo) - | ~~~~~~~~~ + 10 | _ := u8(foo) + | ~~~~~~~ 11 | _ := i8(foo) 12 | _ := i64(foo) vlib/v/checker/tests/struct_type_cast_err.vv:11:7: error: cannot cast struct `Foo` to `i8` 9 | _ := rune(foo) - 10 | _ := byte(foo) + 10 | _ := u8(foo) 11 | _ := i8(foo) | ~~~~~~~ 12 | _ := i64(foo) 13 | _ := int(foo) vlib/v/checker/tests/struct_type_cast_err.vv:12:7: error: cannot cast struct `Foo` to `i64` - 10 | _ := byte(foo) + 10 | _ := u8(foo) 11 | _ := i8(foo) 12 | _ := i64(foo) | ~~~~~~~~ diff --git a/vlib/v/checker/tests/struct_type_cast_err.vv b/vlib/v/checker/tests/struct_type_cast_err.vv index 2a28ae27937ce9..a239df1912b901 100644 --- a/vlib/v/checker/tests/struct_type_cast_err.vv +++ b/vlib/v/checker/tests/struct_type_cast_err.vv @@ -7,7 +7,7 @@ fn main() { _ := u64(foo) _ := u32(foo) _ := rune(foo) - _ := byte(foo) + _ := u8(foo) _ := i8(foo) _ := i64(foo) _ := int(foo) diff --git a/vlib/v/checker/tests/top_level_fn_builtin_decl_err.out b/vlib/v/checker/tests/top_level_fn_builtin_decl_err.out index e0cf2f95b1f964..0a3219f8de1360 100644 --- a/vlib/v/checker/tests/top_level_fn_builtin_decl_err.out +++ b/vlib/v/checker/tests/top_level_fn_builtin_decl_err.out @@ -1,61 +1,55 @@ -vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv:2:12: warning: byte is deprecated, use u8 instead - 1 | @[inline] - 2 | fn char(ch byte) fn (string) !(byte, string) { - | ~~~~ - 3 | return fn [ch] (input string) !(byte, string) { - 4 | return if input[0] == ch { vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv:2:1: error: top level declaration cannot shadow builtin type 1 | @[inline] - 2 | fn char(ch byte) fn (string) !(byte, string) { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 3 | return fn [ch] (input string) !(byte, string) { + 2 | fn char(ch u8) fn (string) !(u8, string) { + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 3 | return fn [ch] (input string) !(u8, string) { 4 | return if input[0] == ch { vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv:18:18: error: unknown function: a_char - 16 | + 16 | 17 | for i, input in inputs { 18 | got, remain := a_char(input)! | ~~~~~~~~~~~~~ - 19 | + 19 | 20 | assert got == 'a'[0] vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv:18:31: error: unexpected `!`, the function `a_char` does not return a Result - 16 | + 16 | 17 | for i, input in inputs { 18 | got, remain := a_char(input)! | ^ - 19 | + 19 | 20 | assert got == 'a'[0] vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv:18:15: error: assignment mismatch: 2 variables but `a_char()` returns 0 values - 16 | + 16 | 17 | for i, input in inputs { 18 | got, remain := a_char(input)! | ~~ - 19 | + 19 | 20 | assert got == 'a'[0] vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv:20:10: error: invalid variable `got` 18 | got, remain := a_char(input)! - 19 | + 19 | 20 | assert got == 'a'[0] | ~~~ 21 | assert remain == remains[i] 22 | } vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv:20:10: error: assert can be used only with `bool` expressions, but found `void` instead 18 | got, remain := a_char(input)! - 19 | + 19 | 20 | assert got == 'a'[0] | ~~~~~~~~~~~~~ 21 | assert remain == remains[i] 22 | } vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv:21:10: error: invalid variable `remain` - 19 | + 19 | 20 | assert got == 'a'[0] 21 | assert remain == remains[i] | ~~~~~~ 22 | } 23 | } vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv:21:10: error: assert can be used only with `bool` expressions, but found `void` instead - 19 | + 19 | 20 | assert got == 'a'[0] 21 | assert remain == remains[i] | ~~~~~~~~~~~~~~~~~~~~ 22 | } - 23 | } + 23 | } \ No newline at end of file diff --git a/vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv b/vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv index c00dfe855a5089..19feae2dea7761 100644 --- a/vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv +++ b/vlib/v/checker/tests/top_level_fn_builtin_decl_err.vv @@ -1,6 +1,6 @@ @[inline] -fn char(ch byte) fn (string) !(byte, string) { - return fn [ch] (input string) !(byte, string) { +fn char(ch u8) fn (string) !(u8, string) { + return fn [ch] (input string) !(u8, string) { return if input[0] == ch { ch, input[1..] } else { diff --git a/vlib/v/checker/tests/use_byte_instead_of_u8_err.out b/vlib/v/checker/tests/use_byte_instead_of_u8_err.out new file mode 100644 index 00000000000000..299fac8363f740 --- /dev/null +++ b/vlib/v/checker/tests/use_byte_instead_of_u8_err.out @@ -0,0 +1,25 @@ +vlib/v/checker/tests/use_byte_instead_of_u8_err.vv:1:13: error: type `byte` is an alias, use the original alias type `u8` instead + 1 | type Byte = byte + | ~~~~ + 2 | + 3 | fn foo(_ byte) {} +vlib/v/checker/tests/use_byte_instead_of_u8_err.vv:3:10: error: byte is deprecated, use u8 instead + 1 | type Byte = byte + 2 | + 3 | fn foo(_ byte) {} + | ~~~~ + 4 | + 5 | fn main() { +vlib/v/checker/tests/use_byte_instead_of_u8_err.vv:6:7: error: byte is deprecated, use u8 instead + 4 | + 5 | fn main() { + 6 | _ := byte(0) + | ~~~~~~~ + 7 | _ := fn(_ byte) {} + 8 | } +vlib/v/checker/tests/use_byte_instead_of_u8_err.vv:7:12: error: byte is deprecated, use u8 instead + 5 | fn main() { + 6 | _ := byte(0) + 7 | _ := fn(_ byte) {} + | ~~~~ + 8 | } diff --git a/vlib/v/checker/tests/use_byte_instead_of_u8_err.vv b/vlib/v/checker/tests/use_byte_instead_of_u8_err.vv new file mode 100644 index 00000000000000..a62fd412a47f98 --- /dev/null +++ b/vlib/v/checker/tests/use_byte_instead_of_u8_err.vv @@ -0,0 +1,8 @@ +type Byte = byte + +fn foo(_ byte) {} + +fn main() { + _ := byte(0) + _ := fn(_ byte) {} +} \ No newline at end of file diff --git a/vlib/v/fmt/tests/import_selective_keep.vv b/vlib/v/fmt/tests/import_selective_keep.vv index 7d3cd8bac59f76..0bc116ee2e2c01 100644 --- a/vlib/v/fmt/tests/import_selective_keep.vv +++ b/vlib/v/fmt/tests/import_selective_keep.vv @@ -11,6 +11,6 @@ fn generic[T]() {} fn main() { _ := Duration(10) // keep cast type - assert *(&f64(&byte(&num) + __offsetof(Complex, re))) == 1.0 + assert *(&f64(&u8(&num) + __offsetof(Complex, re))) == 1.0 generic[Test]() } diff --git a/vlib/v/fmt/tests/pointer_casts_keep.vv b/vlib/v/fmt/tests/pointer_casts_keep.vv index 3f9122bfa7db34..700d2cc207209c 100644 --- a/vlib/v/fmt/tests/pointer_casts_keep.vv +++ b/vlib/v/fmt/tests/pointer_casts_keep.vv @@ -5,10 +5,10 @@ struct Struct { fn main() { unsafe { - pb := &byte(0) - ppb := &&byte(0) - pppb := &&&byte(0) - ppppb := &&&&byte(0) + pb := &u8(0) + ppb := &&u8(0) + pppb := &&&u8(0) + ppppb := &&&&u8(0) dump(voidptr(pb)) dump(voidptr(ppb)) dump(voidptr(pppb))