checker: warn for deprecated methods too (#8861)
parent
5243c5adce
commit
1e71c0eaca
|
@ -1562,6 +1562,15 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
|
||||||
c.warn('method `${left_type_sym.name}.$method_name` must be called from an `unsafe` block',
|
c.warn('method `${left_type_sym.name}.$method_name` must be called from an `unsafe` block',
|
||||||
call_expr.pos)
|
call_expr.pos)
|
||||||
}
|
}
|
||||||
|
if !c.cur_fn.is_deprecated && method.is_deprecated {
|
||||||
|
mut deprecation_message := 'method `${left_type_sym.name}.$method.name` has been deprecated'
|
||||||
|
for attr in method.attrs {
|
||||||
|
if attr.name == 'deprecated' && attr.arg != '' {
|
||||||
|
deprecation_message += '; $attr.arg'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.warn(deprecation_message, call_expr.pos)
|
||||||
|
}
|
||||||
// TODO: typ optimize.. this node can get processed more than once
|
// TODO: typ optimize.. this node can get processed more than once
|
||||||
if call_expr.expected_arg_types.len == 0 {
|
if call_expr.expected_arg_types.len == 0 {
|
||||||
for i in 1 .. method.params.len {
|
for i in 1 .. method.params.len {
|
||||||
|
@ -1783,7 +1792,7 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
|
||||||
c.error('function `$f.name` is private, so you can not import it in module `$c.mod`',
|
c.error('function `$f.name` is private, so you can not import it in module `$c.mod`',
|
||||||
call_expr.pos)
|
call_expr.pos)
|
||||||
}
|
}
|
||||||
if f.is_deprecated {
|
if !c.cur_fn.is_deprecated && f.is_deprecated {
|
||||||
mut deprecation_message := 'function `$f.name` has been deprecated'
|
mut deprecation_message := 'function `$f.name` has been deprecated'
|
||||||
for d in f.attrs {
|
for d in f.attrs {
|
||||||
if d.name == 'deprecated' && d.arg != '' {
|
if d.name == 'deprecated' && d.arg != '' {
|
||||||
|
|
|
@ -11,3 +11,10 @@ vlib/v/checker/tests/use_deprecated_function_warning.vv:13:2: error: function `a
|
||||||
13 | abc()
|
13 | abc()
|
||||||
| ~~~~~
|
| ~~~~~
|
||||||
14 | }
|
14 | }
|
||||||
|
15 |
|
||||||
|
vlib/v/checker/tests/use_deprecated_function_warning.vv:23:4: error: method `S1.m` has been deprecated; use bar instead
|
||||||
|
21 | fn method() {
|
||||||
|
22 | s := S1{}
|
||||||
|
23 | s.m()
|
||||||
|
| ~~~
|
||||||
|
24 | }
|
||||||
|
|
|
@ -12,3 +12,13 @@ fn main() {
|
||||||
xyz()
|
xyz()
|
||||||
abc()
|
abc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct S1 {}
|
||||||
|
|
||||||
|
[deprecated: 'use bar instead']
|
||||||
|
fn (s S1) m() {}
|
||||||
|
|
||||||
|
fn method() {
|
||||||
|
s := S1{}
|
||||||
|
s.m()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue