checker: support a custom `[deprecated: 'message']`
parent
44cb0426f4
commit
8327c9afc1
|
@ -1784,7 +1784,13 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
|
|||
call_expr.pos)
|
||||
}
|
||||
if f.is_deprecated {
|
||||
c.warn('function `$f.name` has been deprecated', call_expr.pos)
|
||||
mut deprecation_message := 'function `$f.name` has been deprecated'
|
||||
for d in f.attrs {
|
||||
if d.name == 'deprecated' && d.arg != '' {
|
||||
deprecation_message += '; $d.arg'
|
||||
}
|
||||
}
|
||||
c.warn(deprecation_message, call_expr.pos)
|
||||
}
|
||||
if f.is_unsafe && !c.inside_unsafe
|
||||
&& (f.language != .c || (f.name[2] in [`m`, `s`] && f.mod == 'builtin')) {
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
vlib/v/checker/tests/use_deprecated_function_warning.vv:3:5: error: function `os.cp_r` has been deprecated
|
||||
1 | import os
|
||||
2 | fn main() {
|
||||
3 | os.cp_r('./aa', './bb', true)
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
4 | }
|
||||
vlib/v/checker/tests/use_deprecated_function_warning.vv:12:2: error: function `xyz` has been deprecated
|
||||
10 |
|
||||
11 | fn main() {
|
||||
12 | xyz()
|
||||
| ~~~~~
|
||||
13 | abc()
|
||||
14 | }
|
||||
vlib/v/checker/tests/use_deprecated_function_warning.vv:13:2: error: function `abc` has been deprecated; use foo2 instead
|
||||
11 | fn main() {
|
||||
12 | xyz()
|
||||
13 | abc()
|
||||
| ~~~~~
|
||||
14 | }
|
||||
|
|
|
@ -1,4 +1,14 @@
|
|||
import os
|
||||
fn main() {
|
||||
os.cp_r('./aa', './bb', true)
|
||||
[deprecated]
|
||||
fn xyz() {
|
||||
println('hi')
|
||||
}
|
||||
|
||||
[deprecated: 'use foo2 instead']
|
||||
fn abc() {
|
||||
println('hi')
|
||||
}
|
||||
|
||||
fn main() {
|
||||
xyz()
|
||||
abc()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue