diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 6ce3198c58..9d4188ea3f 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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', 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 if call_expr.expected_arg_types.len == 0 { 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`', 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' for d in f.attrs { if d.name == 'deprecated' && d.arg != '' { diff --git a/vlib/v/checker/tests/use_deprecated_function_warning.out b/vlib/v/checker/tests/use_deprecated_function_warning.out index cce53f6e23..9cffcba64e 100644 --- a/vlib/v/checker/tests/use_deprecated_function_warning.out +++ b/vlib/v/checker/tests/use_deprecated_function_warning.out @@ -11,3 +11,10 @@ vlib/v/checker/tests/use_deprecated_function_warning.vv:13:2: error: function `a 13 | abc() | ~~~~~ 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 | } diff --git a/vlib/v/checker/tests/use_deprecated_function_warning.vv b/vlib/v/checker/tests/use_deprecated_function_warning.vv index 6a72a2ad92..d5f95ef09e 100644 --- a/vlib/v/checker/tests/use_deprecated_function_warning.vv +++ b/vlib/v/checker/tests/use_deprecated_function_warning.vv @@ -12,3 +12,13 @@ fn main() { xyz() abc() } + +struct S1 {} + +[deprecated: 'use bar instead'] +fn (s S1) m() {} + +fn method() { + s := S1{} + s.m() +}