checker: support a custom `[deprecated: 'message']`

pull/8898/head
Delyan Angelov 2021-02-20 17:35:29 +02:00
parent 44cb0426f4
commit 8327c9afc1
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 33 additions and 10 deletions

View File

@ -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')) {

View File

@ -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 | }

View File

@ -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()
}