1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: add byte deprecation warning (#18287)

This commit is contained in:
Turiiya 2023-05-28 23:30:32 +02:00 committed by GitHub
parent 3ac63cce86
commit 1be539d20f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -702,6 +702,9 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
&& right is ast.StructInit && (right as ast.StructInit).is_anon {
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())
}
}
// this needs to run after the assign stmt left exprs have been run through checker
// so that ident.obj is set

View File

@ -1,3 +1,10 @@
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{}