From c70e6af62d9168e4e103a182f5a979faee8e1579 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Tue, 12 Jan 2021 18:25:22 -0500 Subject: [PATCH 1/7] Support applying annotations on aliases and annotations --- .../crystal/semantic/cleanup_transformer.cr | 12 ++++ .../crystal/semantic/top_level_visitor.cr | 11 +++- src/compiler/crystal/semantic/warnings.cr | 60 +++++++++++++++++++ src/compiler/crystal/syntax/ast.cr | 4 ++ 4 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/compiler/crystal/semantic/cleanup_transformer.cr b/src/compiler/crystal/semantic/cleanup_transformer.cr index bec5189dab34..130071a54fae 100644 --- a/src/compiler/crystal/semantic/cleanup_transformer.cr +++ b/src/compiler/crystal/semantic/cleanup_transformer.cr @@ -114,6 +114,18 @@ module Crystal {@last_is_truthy, @last_is_falsey} end + def transform(node : Alias) + @program.check_call_to_deprecated_alias node + + node + end + + def transform(node : AnnotationDef) + @program.check_call_to_deprecated_annotation node + + node + end + def transform(node : Def) node.hook_expansions.try &.map! &.transform self node diff --git a/src/compiler/crystal/semantic/top_level_visitor.cr b/src/compiler/crystal/semantic/top_level_visitor.cr index dbab62314a92..1a6393794ef3 100644 --- a/src/compiler/crystal/semantic/top_level_visitor.cr +++ b/src/compiler/crystal/semantic/top_level_visitor.cr @@ -275,6 +275,11 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor def visit(node : AnnotationDef) check_outside_exp node, "declare annotation" + annotations = read_annotations + process_annotations(annotations) do |annotation_type, ann| + node.add_annotation(annotation_type, ann) + end + scope, name, type = lookup_type_def(node) if type @@ -286,7 +291,7 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor scope.types[name] = type end - attach_doc type, node, annotations: nil + attach_doc type, node, annotations false end @@ -296,6 +301,10 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor annotations = read_annotations + process_annotations(annotations) do |annotation_type, ann| + node.add_annotation(annotation_type, ann) + end + scope, name, existing_type = lookup_type_def(node) if existing_type diff --git a/src/compiler/crystal/semantic/warnings.cr b/src/compiler/crystal/semantic/warnings.cr index 5516c605bb45..8b399b83daad 100644 --- a/src/compiler/crystal/semantic/warnings.cr +++ b/src/compiler/crystal/semantic/warnings.cr @@ -14,6 +14,8 @@ module Crystal @deprecated_methods_detected = Set(String).new @deprecated_macros_detected = Set(String).new + @deprecated_aliases_detected = Set(String).new + @deprecated_annotations_detected = Set(String).new def report_warning(node : ASTNode, message : String) return unless self.warnings.all? @@ -48,6 +50,50 @@ module Crystal end end + def check_call_to_deprecated_alias(node : Alias) : Nil + return unless @warnings.all? + + if (ann = node.annotation(deprecated_annotation)) && (deprecated_annotation = DeprecatedAnnotation.from(ann)) + return if ignore_warning_due_to_location?(node.location) + short_reference = node.short_reference + warning_key = node.location.try { |l| "#{short_reference} #{l}" } + + # skip warning if the call site was already informed + # if there is no location information just inform it. + return if !warning_key || @deprecated_aliases_detected.includes?(warning_key) + @deprecated_aliases_detected.add(warning_key) if warning_key + + message = deprecated_annotation.message + message = message ? " #{message}" : "" + + full_message = node.warning "Deprecated #{short_reference}.#{message}" + + self.warning_failures << full_message + end + end + + def check_call_to_deprecated_annotation(node : AnnotationDef) : Nil + return unless @warnings.all? + + if (ann = node.annotation(deprecated_annotation)) && (deprecated_annotation = DeprecatedAnnotation.from(ann)) + return if ignore_warning_due_to_location?(node.location) + short_reference = node.short_reference + warning_key = node.location.try { |l| "#{short_reference} #{l}" } + + # skip warning if the call site was already informed + # if there is no location information just inform it. + return if !warning_key || @deprecated_annotations_detected.includes?(warning_key) + @deprecated_annotations_detected.add(warning_key) if warning_key + + message = deprecated_annotation.message + message = message ? " #{message}" : "" + + full_message = node.warning "Deprecated #{short_reference}.#{message}" + + self.warning_failures << full_message + end + end + def check_call_to_deprecated_macro(a_macro : Macro, call : Call) return unless self.warnings.all? @@ -105,6 +151,20 @@ module Crystal end end + class Alias + def short_reference + # TODO: Define `#owner` on `self`. + "alias #{name}" + end + end + + class AnnotationDef + def short_reference + # TODO: Define `#owner` on `self`. + "annotation #{name}" + end + end + class Macro def short_reference case owner diff --git a/src/compiler/crystal/syntax/ast.cr b/src/compiler/crystal/syntax/ast.cr index 6a4c79a75bd5..ec9c17324efe 100644 --- a/src/compiler/crystal/syntax/ast.cr +++ b/src/compiler/crystal/syntax/ast.cr @@ -1378,6 +1378,8 @@ module Crystal # 'end' # class AnnotationDef < ASTNode + include Annotatable + property name : Path property doc : String? property name_location : Location? @@ -1899,6 +1901,8 @@ module Crystal end class Alias < ASTNode + include Annotatable + property name : Path property value : ASTNode property doc : String? From df49a26ff054986cb8d8e91371cf2e41a400f81b Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Thu, 14 Jan 2021 20:32:33 -0500 Subject: [PATCH 2/7] Refactor warnings to reduce duplication Add specs for aliases and annotations --- spec/compiler/codegen/warnings_spec.cr | 54 +++++++++++++ spec/compiler/semantic/warnings_spec.cr | 54 +++++++++++++ src/compiler/crystal/semantic/warnings.cr | 95 +++++++---------------- 3 files changed, 138 insertions(+), 65 deletions(-) diff --git a/spec/compiler/codegen/warnings_spec.cr b/spec/compiler/codegen/warnings_spec.cr index ec7a5885dafa..0bd704448598 100644 --- a/spec/compiler/codegen/warnings_spec.cr +++ b/spec/compiler/codegen/warnings_spec.cr @@ -125,6 +125,60 @@ describe "Code gen: warnings" do "warning in line 7\nWarning: Deprecated Foo.new:a." end + it "detects deprecated aliases" do + assert_warning <<-CR, + struct SomeType; end + + @[Deprecated] + alias OtherType = SomeType + + OtherType.new + CR + "warning in line 4\nWarning: Deprecated alias OtherType." + end + + pending "detects deprecated namespaced aliases" do + assert_warning <<-CR, + struct SomeType; end + + module MyNamespace + @[Deprecated] + alias OtherType = SomeType + end + + MyNamespace::OtherType.new + CR + "warning in line 4\nWarning: Deprecated alias MyNamespace::OtherType." + end + + it "detects deprecated annotations" do + assert_warning <<-CR, + @[Deprecated] + annotation Foo; end + + @[Foo] + def bar ;end + + bar + CR + "warning in line 2\nWarning: Deprecated annotation Foo." + end + + pending "detects deprecated namespaced annotations" do + assert_warning <<-CR, + module MyNamespace + @[Deprecated] + annotation Foo; end + end + + @[MyNamespace::Foo] + def bar ;end + + bar + CR + "warning in line 2\nWarning: Deprecated annotation MyNamespace::Foo." + end + it "informs warnings once per call site location (a)" do warning_failures = warnings_result <<-CR class Foo diff --git a/spec/compiler/semantic/warnings_spec.cr b/spec/compiler/semantic/warnings_spec.cr index 77157bab5237..9831fd712bee 100644 --- a/spec/compiler/semantic/warnings_spec.cr +++ b/spec/compiler/semantic/warnings_spec.cr @@ -125,6 +125,60 @@ describe "Semantic: warnings" do "warning in line 7\nWarning: Deprecated Foo.new:a." end + it "detects deprecated aliases" do + assert_warning <<-CR, + struct SomeType; end + + @[Deprecated] + alias OtherType = SomeType + + OtherType.new + CR + "warning in line 4\nWarning: Deprecated alias OtherType." + end + + pending "detects deprecated namespaced aliases" do + assert_warning <<-CR, + struct SomeType; end + + module MyNamespace + @[Deprecated] + alias OtherType = SomeType + end + + MyNamespace::OtherType.new + CR + "warning in line 4\nWarning: Deprecated alias MyNamespace::OtherType." + end + + it "detects deprecated annotations" do + assert_warning <<-CR, + @[Deprecated] + annotation Foo; end + + @[Foo] + def bar ;end + + bar + CR + "warning in line 2\nWarning: Deprecated annotation Foo." + end + + pending "detects deprecated namespaced annotations" do + assert_warning <<-CR, + module MyNamespace + @[Deprecated] + annotation Foo; end + end + + @[MyNamespace::Foo] + def bar ;end + + bar + CR + "warning in line 2\nWarning: Deprecated annotation MyNamespace::Foo." + end + it "informs warnings once per call site location (a)" do warning_failures = warnings_result <<-CR class Foo diff --git a/src/compiler/crystal/semantic/warnings.cr b/src/compiler/crystal/semantic/warnings.cr index 8b399b83daad..a61973b7afa1 100644 --- a/src/compiler/crystal/semantic/warnings.cr +++ b/src/compiler/crystal/semantic/warnings.cr @@ -54,21 +54,9 @@ module Crystal return unless @warnings.all? if (ann = node.annotation(deprecated_annotation)) && (deprecated_annotation = DeprecatedAnnotation.from(ann)) - return if ignore_warning_due_to_location?(node.location) - short_reference = node.short_reference - warning_key = node.location.try { |l| "#{short_reference} #{l}" } - - # skip warning if the call site was already informed - # if there is no location information just inform it. - return if !warning_key || @deprecated_aliases_detected.includes?(warning_key) - @deprecated_aliases_detected.add(warning_key) if warning_key - - message = deprecated_annotation.message - message = message ? " #{message}" : "" - - full_message = node.warning "Deprecated #{short_reference}.#{message}" - - self.warning_failures << full_message + self.validate_call_to_deprecated_node node, node.location, node.short_reference, deprecated_annotation do |warning_key| + @deprecated_aliases_detected.add? warning_key + end end end @@ -76,46 +64,21 @@ module Crystal return unless @warnings.all? if (ann = node.annotation(deprecated_annotation)) && (deprecated_annotation = DeprecatedAnnotation.from(ann)) - return if ignore_warning_due_to_location?(node.location) - short_reference = node.short_reference - warning_key = node.location.try { |l| "#{short_reference} #{l}" } - - # skip warning if the call site was already informed - # if there is no location information just inform it. - return if !warning_key || @deprecated_annotations_detected.includes?(warning_key) - @deprecated_annotations_detected.add(warning_key) if warning_key - - message = deprecated_annotation.message - message = message ? " #{message}" : "" - - full_message = node.warning "Deprecated #{short_reference}.#{message}" - - self.warning_failures << full_message + self.validate_call_to_deprecated_node node, node.location, node.short_reference, deprecated_annotation do |warning_key| + @deprecated_annotations_detected.add? warning_key + end end end - def check_call_to_deprecated_macro(a_macro : Macro, call : Call) - return unless self.warnings.all? + def check_call_to_deprecated_macro(node : Macro, call : Call) + return unless @warnings.all? - if (ann = a_macro.annotation(self.deprecated_annotation)) && - (deprecated_annotation = DeprecatedAnnotation.from(ann)) + if (ann = node.annotation(self.deprecated_annotation)) && (deprecated_annotation = DeprecatedAnnotation.from(ann)) call_location = call.location.try(&.macro_location) || call.location - return if self.ignore_warning_due_to_location?(call_location) - short_reference = a_macro.short_reference - warning_key = call_location.try { |l| "#{short_reference} #{l}" } - - # skip warning if the call site was already informed - # if there is no location information just inform it. - return if !warning_key || @deprecated_macros_detected.includes?(warning_key) - @deprecated_macros_detected.add(warning_key) if warning_key - - message = deprecated_annotation.message - message = message ? " #{message}" : "" - - full_message = call.warning "Deprecated #{short_reference}.#{message}" - - self.warning_failures << full_message + self.validate_call_to_deprecated_node call, call_location, node.short_reference, deprecated_annotation do |warning_key| + @deprecated_macros_detected.add? warning_key + end end end @@ -123,26 +86,28 @@ module Crystal return unless @warnings.all? node.target_defs.try &.each do |target_def| - if (ann = target_def.annotation(deprecated_annotation)) && - (deprecated_annotation = DeprecatedAnnotation.from(ann)) - return if compiler_expanded_call(node) - return if ignore_warning_due_to_location?(node.location) - short_reference = target_def.short_reference - warning_key = node.location.try { |l| "#{short_reference} #{l}" } + if (ann = target_def.annotation(deprecated_annotation)) && (deprecated_annotation = DeprecatedAnnotation.from(ann)) + return if self.compiler_expanded_call(node) - # skip warning if the call site was already informed - # if there is no location information just inform it. - return if !warning_key || @deprecated_methods_detected.includes?(warning_key) - @deprecated_methods_detected.add(warning_key) if warning_key + self.validate_call_to_deprecated_node node, node.location, target_def.short_reference, deprecated_annotation do |warning_key| + @deprecated_methods_detected.add? warning_key + end + end + end + end - message = deprecated_annotation.message - message = message ? " #{message}" : "" + private def validate_call_to_deprecated_node(node : ASTNode, location : Location?, short_reference : String, deprecated_annotation : DeprecatedAnnotation, & : String -> Bool) : Nil + return if self.ignore_warning_due_to_location? location + warning_key = location.try { |l| "#{short_reference} #{l}" } - full_message = node.warning "Deprecated #{short_reference}.#{message}" + # skip warning if the call site was already informed + # if there is no location information just inform it. + return if !warning_key || !yield(warning_key) - self.warning_failures << full_message - end - end + message = deprecated_annotation.message + message = message ? " #{message}" : "" + + self.warning_failures << node.warning "Deprecated #{short_reference}.#{message}" end private def compiler_expanded_call(node : Call) From 34c26d8474b5c25279f89006b12e6fa1827bbcbd Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Thu, 14 Jan 2021 22:16:12 -0500 Subject: [PATCH 3/7] Move includes to the correct ast.cr file --- src/compiler/crystal/semantic/ast.cr | 6 ++++++ src/compiler/crystal/syntax/ast.cr | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/crystal/semantic/ast.cr b/src/compiler/crystal/semantic/ast.cr index 1ce97c89995e..62e2f894ccd1 100644 --- a/src/compiler/crystal/semantic/ast.cr +++ b/src/compiler/crystal/semantic/ast.cr @@ -657,9 +657,15 @@ module Crystal end class Alias + include Annotatable + property! resolved_type : AliasType end + class AnnotationDef + include Annotatable + end + class External < Def property real_name : String property! fun_def : FunDef diff --git a/src/compiler/crystal/syntax/ast.cr b/src/compiler/crystal/syntax/ast.cr index ec9c17324efe..6a4c79a75bd5 100644 --- a/src/compiler/crystal/syntax/ast.cr +++ b/src/compiler/crystal/syntax/ast.cr @@ -1378,8 +1378,6 @@ module Crystal # 'end' # class AnnotationDef < ASTNode - include Annotatable - property name : Path property doc : String? property name_location : Location? @@ -1901,8 +1899,6 @@ module Crystal end class Alias < ASTNode - include Annotatable - property name : Path property value : ASTNode property doc : String? From a25dbdd63da6d223f6fb512e0bb114a9d442e5d6 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Tue, 6 Apr 2021 21:25:17 -0400 Subject: [PATCH 4/7] Support namespaced aliases and annotations --- spec/compiler/codegen/warnings_spec.cr | 12 ++++++------ spec/compiler/semantic/warnings_spec.cr | 12 ++++++------ src/compiler/crystal/semantic/ast.cr | 2 ++ src/compiler/crystal/semantic/top_level_visitor.cr | 2 ++ src/compiler/crystal/semantic/warnings.cr | 6 ++---- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/spec/compiler/codegen/warnings_spec.cr b/spec/compiler/codegen/warnings_spec.cr index 0bd704448598..b9e896b51fe9 100644 --- a/spec/compiler/codegen/warnings_spec.cr +++ b/spec/compiler/codegen/warnings_spec.cr @@ -137,7 +137,7 @@ describe "Code gen: warnings" do "warning in line 4\nWarning: Deprecated alias OtherType." end - pending "detects deprecated namespaced aliases" do + it "detects deprecated namespaced aliases" do assert_warning <<-CR, struct SomeType; end @@ -148,7 +148,7 @@ describe "Code gen: warnings" do MyNamespace::OtherType.new CR - "warning in line 4\nWarning: Deprecated alias MyNamespace::OtherType." + "warning in line 5\nWarning: Deprecated alias MyNamespace::OtherType." end it "detects deprecated annotations" do @@ -157,14 +157,14 @@ describe "Code gen: warnings" do annotation Foo; end @[Foo] - def bar ;end + def bar; end bar CR "warning in line 2\nWarning: Deprecated annotation Foo." end - pending "detects deprecated namespaced annotations" do + it "detects deprecated namespaced annotations" do assert_warning <<-CR, module MyNamespace @[Deprecated] @@ -172,11 +172,11 @@ describe "Code gen: warnings" do end @[MyNamespace::Foo] - def bar ;end + def bar; end bar CR - "warning in line 2\nWarning: Deprecated annotation MyNamespace::Foo." + "warning in line 3\nWarning: Deprecated annotation MyNamespace::Foo." end it "informs warnings once per call site location (a)" do diff --git a/spec/compiler/semantic/warnings_spec.cr b/spec/compiler/semantic/warnings_spec.cr index 9831fd712bee..99738c1bb86a 100644 --- a/spec/compiler/semantic/warnings_spec.cr +++ b/spec/compiler/semantic/warnings_spec.cr @@ -137,7 +137,7 @@ describe "Semantic: warnings" do "warning in line 4\nWarning: Deprecated alias OtherType." end - pending "detects deprecated namespaced aliases" do + it "detects deprecated namespaced aliases" do assert_warning <<-CR, struct SomeType; end @@ -148,7 +148,7 @@ describe "Semantic: warnings" do MyNamespace::OtherType.new CR - "warning in line 4\nWarning: Deprecated alias MyNamespace::OtherType." + "warning in line 5\nWarning: Deprecated alias MyNamespace::OtherType." end it "detects deprecated annotations" do @@ -157,14 +157,14 @@ describe "Semantic: warnings" do annotation Foo; end @[Foo] - def bar ;end + def bar; end bar CR "warning in line 2\nWarning: Deprecated annotation Foo." end - pending "detects deprecated namespaced annotations" do + it "detects deprecated namespaced annotations" do assert_warning <<-CR, module MyNamespace @[Deprecated] @@ -172,11 +172,11 @@ describe "Semantic: warnings" do end @[MyNamespace::Foo] - def bar ;end + def bar; end bar CR - "warning in line 2\nWarning: Deprecated annotation MyNamespace::Foo." + "warning in line 3\nWarning: Deprecated annotation MyNamespace::Foo." end it "informs warnings once per call site location (a)" do diff --git a/src/compiler/crystal/semantic/ast.cr b/src/compiler/crystal/semantic/ast.cr index 62e2f894ccd1..c38039782f35 100644 --- a/src/compiler/crystal/semantic/ast.cr +++ b/src/compiler/crystal/semantic/ast.cr @@ -664,6 +664,8 @@ module Crystal class AnnotationDef include Annotatable + + property! resolved_type : AnnotationType end class External < Def diff --git a/src/compiler/crystal/semantic/top_level_visitor.cr b/src/compiler/crystal/semantic/top_level_visitor.cr index 1a6393794ef3..e7fbf2ddf82e 100644 --- a/src/compiler/crystal/semantic/top_level_visitor.cr +++ b/src/compiler/crystal/semantic/top_level_visitor.cr @@ -291,6 +291,8 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor scope.types[name] = type end + node.resolved_type = type + attach_doc type, node, annotations false diff --git a/src/compiler/crystal/semantic/warnings.cr b/src/compiler/crystal/semantic/warnings.cr index a61973b7afa1..4086c11bc6f1 100644 --- a/src/compiler/crystal/semantic/warnings.cr +++ b/src/compiler/crystal/semantic/warnings.cr @@ -118,15 +118,13 @@ module Crystal class Alias def short_reference - # TODO: Define `#owner` on `self`. - "alias #{name}" + "alias #{resolved_type}" end end class AnnotationDef def short_reference - # TODO: Define `#owner` on `self`. - "annotation #{name}" + "annotation #{resolved_type}" end end From a6dfb582d16bb99cb1ccf76838dea06d302f9142 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Tue, 4 Oct 2022 15:21:58 +0800 Subject: [PATCH 5/7] Remove dead code and minimise diff --- src/compiler/crystal/semantic/warnings.cr | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/compiler/crystal/semantic/warnings.cr b/src/compiler/crystal/semantic/warnings.cr index 777cbc30e2ba..3f5c857bcf0a 100644 --- a/src/compiler/crystal/semantic/warnings.cr +++ b/src/compiler/crystal/semantic/warnings.cr @@ -17,10 +17,10 @@ module Crystal check_deprecation(const, node, @deprecated_constants_detected) end - def check_call_to_deprecated_macro(node : Macro, call : Call) + def check_call_to_deprecated_macro(a_macro : Macro, call : Call) return unless @warnings.level.all? - check_deprecation(node, call, @deprecated_macros_detected) + check_deprecation(a_macro, call, @deprecated_macros_detected) end def check_call_to_deprecated_method(node : Call) @@ -67,20 +67,6 @@ module Crystal end end - private def validate_call_to_deprecated_node(node : ASTNode, location : Location?, short_reference : String, deprecated_annotation : DeprecatedAnnotation, & : String -> Bool) : Nil - return if self.ignore_warning_due_to_location? location - warning_key = location.try { |l| "#{short_reference} #{l}" } - - # skip warning if the call site was already informed - # if there is no location information just inform it. - return if !warning_key || !yield(warning_key) - - message = deprecated_annotation.message - message = message ? " #{message}" : "" - - self.warning_failures << node.warning "Deprecated #{short_reference}.#{message}" - end - private def compiler_expanded_call(node : Call) # Compiler generates a `_.initialize` call in `new` node.obj.as?(Var).try { |v| v.name == "_" } && node.name == "initialize" From 0c302293dfaa278c316fbe8bb5248928522765a4 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Wed, 5 Oct 2022 16:43:33 +0800 Subject: [PATCH 6/7] Remove work on alias deprecation --- spec/compiler/semantic/warnings_spec.cr | 28 ------------------- src/compiler/crystal/semantic/ast.cr | 2 -- .../crystal/semantic/cleanup_transformer.cr | 6 ---- .../crystal/semantic/top_level_visitor.cr | 4 --- src/compiler/crystal/semantic/warnings.cr | 13 --------- 5 files changed, 53 deletions(-) diff --git a/spec/compiler/semantic/warnings_spec.cr b/spec/compiler/semantic/warnings_spec.cr index d30114314293..7c2aadd22806 100644 --- a/spec/compiler/semantic/warnings_spec.cr +++ b/spec/compiler/semantic/warnings_spec.cr @@ -1,34 +1,6 @@ require "../spec_helper" describe "Semantic: warnings" do - describe "deprecated aliases" do - it "detects deprecated aliases" do - assert_warning <<-CR, - struct SomeType; end - - @[Deprecated] - alias OtherType = SomeType - - OtherType.new - CR - "warning in line 4\nWarning: Deprecated alias OtherType." - end - - it "detects deprecated namespaced aliases" do - assert_warning <<-CR, - struct SomeType; end - - module MyNamespace - @[Deprecated] - alias OtherType = SomeType - end - - MyNamespace::OtherType.new - CR - "warning in line 5\nWarning: Deprecated alias MyNamespace::OtherType." - end - end - describe "deprecated annotations" do it "detects deprecated annotations" do assert_warning <<-CR, diff --git a/src/compiler/crystal/semantic/ast.cr b/src/compiler/crystal/semantic/ast.cr index a93bf06b2c46..30f6a864170a 100644 --- a/src/compiler/crystal/semantic/ast.cr +++ b/src/compiler/crystal/semantic/ast.cr @@ -675,8 +675,6 @@ module Crystal end class Alias - include Annotatable - property! resolved_type : AliasType end diff --git a/src/compiler/crystal/semantic/cleanup_transformer.cr b/src/compiler/crystal/semantic/cleanup_transformer.cr index 3b213a37f5fa..3f37787f7811 100644 --- a/src/compiler/crystal/semantic/cleanup_transformer.cr +++ b/src/compiler/crystal/semantic/cleanup_transformer.cr @@ -126,12 +126,6 @@ module Crystal {@last_is_truthy, @last_is_falsey} end - def transform(node : Alias) - @program.check_call_to_deprecated_alias node - - node - end - def transform(node : AnnotationDef) @program.check_call_to_deprecated_annotation node diff --git a/src/compiler/crystal/semantic/top_level_visitor.cr b/src/compiler/crystal/semantic/top_level_visitor.cr index 61978ad11047..05b64770acfb 100644 --- a/src/compiler/crystal/semantic/top_level_visitor.cr +++ b/src/compiler/crystal/semantic/top_level_visitor.cr @@ -303,10 +303,6 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor annotations = read_annotations - process_annotations(annotations) do |annotation_type, ann| - node.add_annotation(annotation_type, ann) - end - scope, name, existing_type = lookup_type_def(node) if existing_type diff --git a/src/compiler/crystal/semantic/warnings.cr b/src/compiler/crystal/semantic/warnings.cr index 3f5c857bcf0a..b3ac03b6eb4f 100644 --- a/src/compiler/crystal/semantic/warnings.cr +++ b/src/compiler/crystal/semantic/warnings.cr @@ -8,7 +8,6 @@ module Crystal @deprecated_constants_detected = Set(String).new @deprecated_methods_detected = Set(String).new @deprecated_macros_detected = Set(String).new - @deprecated_aliases_detected = Set(String).new @deprecated_annotations_detected = Set(String).new def check_deprecated_constant(const : Const, node : Path) @@ -32,12 +31,6 @@ module Crystal end end - def check_call_to_deprecated_alias(node : Alias) : Nil - return unless @warnings.level.all? - - check_deprecation(node, node.name, @deprecated_aliases_detected) - end - def check_call_to_deprecated_annotation(node : AnnotationDef) : Nil return unless @warnings.level.all? @@ -73,12 +66,6 @@ module Crystal end end - class Alias - def short_reference - "alias #{resolved_type}" - end - end - class AnnotationDef def short_reference "annotation #{resolved_type}" From cc386a9b367cb2328cf502df0da0022595f128c3 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Wed, 5 Oct 2022 16:46:21 +0800 Subject: [PATCH 7/7] Fix copy-paste induced error --- src/compiler/crystal/semantic/warnings.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/crystal/semantic/warnings.cr b/src/compiler/crystal/semantic/warnings.cr index b3ac03b6eb4f..437632bc9953 100644 --- a/src/compiler/crystal/semantic/warnings.cr +++ b/src/compiler/crystal/semantic/warnings.cr @@ -34,7 +34,7 @@ module Crystal def check_call_to_deprecated_annotation(node : AnnotationDef) : Nil return unless @warnings.level.all? - check_deprecation(node, node.name, @deprecated_aliases_detected) + check_deprecation(node, node.name, @deprecated_annotations_detected) end private def check_deprecation(object, use_site, detects)