checker: check deprecated functions
parent
db28796b5f
commit
7efb3ecb34
|
@ -1307,7 +1307,8 @@ pub fn (s string) limit(max int) string {
|
||||||
|
|
||||||
[deprecated]
|
[deprecated]
|
||||||
pub fn (c byte) is_white() bool {
|
pub fn (c byte) is_white() bool {
|
||||||
panic('Use `string.is_space` instead of `string.is_white')
|
eprintln('warning: `string.is_white` has been deprecated, use `string.is_space` instead')
|
||||||
|
return c.is_space()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (s string) hash() int {
|
pub fn (s string) hash() int {
|
||||||
|
|
15
vlib/os/os.v
15
vlib/os/os.v
|
@ -204,7 +204,8 @@ pub fn cp(old, new string) ?bool {
|
||||||
|
|
||||||
[deprecated]
|
[deprecated]
|
||||||
pub fn cp_r(osource_path, odest_path string, overwrite bool) ?bool {
|
pub fn cp_r(osource_path, odest_path string, overwrite bool) ?bool {
|
||||||
panic('Use `os.cp_all` instead of `os.cp_r`')
|
eprintln('warning: `os.cp_r` has been deprecated, use `os.cp_all` instead')
|
||||||
|
return cp_all(osource_path, odest_path, overwrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cp_all(osource_path, odest_path string, overwrite bool) ?bool {
|
pub fn cp_all(osource_path, odest_path string, overwrite bool) ?bool {
|
||||||
|
@ -622,7 +623,8 @@ pub fn is_readable(path string) bool {
|
||||||
|
|
||||||
[deprecated]
|
[deprecated]
|
||||||
pub fn file_exists(_path string) bool {
|
pub fn file_exists(_path string) bool {
|
||||||
panic('Use `os.exists` instead of `os.file_exists`')
|
eprintln('warning: `os.file_exists` has been deprecated, use `os.exists` instead')
|
||||||
|
return exists(_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// rm removes file in `path`.
|
// rm removes file in `path`.
|
||||||
|
@ -645,7 +647,8 @@ pub fn rmdir(path string) {
|
||||||
|
|
||||||
[deprecated]
|
[deprecated]
|
||||||
pub fn rmdir_recursive(path string) {
|
pub fn rmdir_recursive(path string) {
|
||||||
panic('Use `os.rmdir_all` instead of `os.rmdir_recursive`')
|
eprintln('warning: `os.rmdir_recursive` has been deprecated, use `os.rmdir_all` instead')
|
||||||
|
rmdir_all(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rmdir_all(path string) {
|
pub fn rmdir_all(path string) {
|
||||||
|
@ -1004,7 +1007,8 @@ pub fn exists_in_system_path(prog string) bool {
|
||||||
|
|
||||||
[deprecated]
|
[deprecated]
|
||||||
pub fn dir_exists(path string) bool {
|
pub fn dir_exists(path string) bool {
|
||||||
panic('Use `os.is_dir` instead of `os.dir_exists`')
|
eprintln('warning: `os.dir_exists` has been deprecated, use `os.is_dir` instead')
|
||||||
|
return is_dir(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// is_dir returns a boolean indicating whether the given path is a directory.
|
// is_dir returns a boolean indicating whether the given path is a directory.
|
||||||
|
@ -1198,7 +1202,8 @@ pub fn log(s string) {
|
||||||
|
|
||||||
[deprecated]
|
[deprecated]
|
||||||
pub fn flush_stdout() {
|
pub fn flush_stdout() {
|
||||||
panic('Use `os.flush` instead of `os.flush_stdout`')
|
eprintln('warning: `os.flush_stdout` has been deprecated, use `os.flush` instead')
|
||||||
|
flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flush() {
|
pub fn flush() {
|
||||||
|
|
|
@ -999,6 +999,9 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
|
||||||
if !f.is_pub && f.language == .v && f.name.len > 0 && f.mod.len > 0 && f.mod != c.mod {
|
if !f.is_pub && f.language == .v && f.name.len > 0 && f.mod.len > 0 && f.mod != c.mod {
|
||||||
c.error('function `$f.name` is private. curmod=$c.mod fmod=$f.mod', call_expr.pos)
|
c.error('function `$f.name` is private. curmod=$c.mod fmod=$f.mod', call_expr.pos)
|
||||||
}
|
}
|
||||||
|
if f.is_deprecated {
|
||||||
|
c.warn('function `$f.name` has been deprecated', call_expr.pos)
|
||||||
|
}
|
||||||
call_expr.return_type = f.return_type
|
call_expr.return_type = f.return_type
|
||||||
if f.return_type == table.void_type && f.ctdefine.len > 0 && f.ctdefine !in c.pref.compile_defines {
|
if f.return_type == table.void_type && f.ctdefine.len > 0 && f.ctdefine !in c.pref.compile_defines {
|
||||||
call_expr.should_be_skipped = true
|
call_expr.should_be_skipped = true
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/checker/tests/use_deprecated_function_warning.v:3:5: error: function `os.cp_r` has been deprecated
|
||||||
|
1 | import os
|
||||||
|
2 | fn main() {
|
||||||
|
3 | os.cp_r('./aa', './bb', true)
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
4 | }
|
|
@ -0,0 +1,4 @@
|
||||||
|
import os
|
||||||
|
fn main() {
|
||||||
|
os.cp_r('./aa', './bb', true)
|
||||||
|
}
|
|
@ -235,6 +235,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
is_variadic: is_variadic
|
is_variadic: is_variadic
|
||||||
is_generic: is_generic
|
is_generic: is_generic
|
||||||
is_pub: is_pub
|
is_pub: is_pub
|
||||||
|
is_deprecated: is_deprecated
|
||||||
ctdefine: ctdefine
|
ctdefine: ctdefine
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -256,6 +257,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
language: language
|
language: language
|
||||||
is_generic: is_generic
|
is_generic: is_generic
|
||||||
is_pub: is_pub
|
is_pub: is_pub
|
||||||
|
is_deprecated: is_deprecated
|
||||||
ctdefine: ctdefine
|
ctdefine: ctdefine
|
||||||
mod: p.mod
|
mod: p.mod
|
||||||
})
|
})
|
||||||
|
|
|
@ -21,14 +21,15 @@ pub mut:
|
||||||
|
|
||||||
pub struct Fn {
|
pub struct Fn {
|
||||||
pub:
|
pub:
|
||||||
args []Arg
|
args []Arg
|
||||||
return_type Type
|
return_type Type
|
||||||
is_variadic bool
|
is_variadic bool
|
||||||
language Language
|
language Language
|
||||||
is_generic bool
|
is_generic bool
|
||||||
is_pub bool
|
is_pub bool
|
||||||
mod string
|
is_deprecated bool
|
||||||
ctdefine string // compile time define. myflag, when [if myflag] tag
|
mod string
|
||||||
|
ctdefine string // compile time define. myflag, when [if myflag] tag
|
||||||
pub mut:
|
pub mut:
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue