diff --git a/spec/compiler/semantic/warnings_spec.cr b/spec/compiler/semantic/warnings_spec.cr index c9b606b36a35..502351ce305b 100644 --- a/spec/compiler/semantic/warnings_spec.cr +++ b/spec/compiler/semantic/warnings_spec.cr @@ -267,6 +267,19 @@ describe "Semantic: warnings" do end end + it "ignores nested calls to deprecated methods" do + x = assert_warning <<-CRYSTAL, + @[Deprecated] + def foo; bar; end + + @[Deprecated] + def bar; end + + foo + CRYSTAL + "warning in line 7\nWarning: Deprecated top-level foo." + end + it "errors if invalid argument type" do assert_error <<-CRYSTAL, @[Deprecated(42)] diff --git a/src/compiler/crystal/semantic/cleanup_transformer.cr b/src/compiler/crystal/semantic/cleanup_transformer.cr index 0126c62d1166..70a8ffe63590 100644 --- a/src/compiler/crystal/semantic/cleanup_transformer.cr +++ b/src/compiler/crystal/semantic/cleanup_transformer.cr @@ -464,7 +464,9 @@ module Crystal return expanded.transform self end - @program.check_call_to_deprecated_method(node) + unless @current_def.try(&.annotation(@program.deprecated_annotation)) + @program.check_call_to_deprecated_method(node) + end # Need to transform these manually because node.block doesn't # need to be transformed if it has a fun_literal