Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Crystal::Program#check_deprecation #11684

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 25 additions & 37 deletions src/compiler/crystal/semantic/warnings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -49,53 +49,41 @@ module Crystal
end

def check_call_to_deprecated_macro(a_macro : Macro, call : Call)
return unless self.warnings.all?

if (ann = a_macro.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}"
return unless @warnings.all?

self.warning_failures << full_message
end
check_deprecation(a_macro, call, @deprecated_macros_detected)
end

def check_call_to_deprecated_method(node : Call)
return unless @warnings.all?
return if compiler_expanded_call(node)

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

# 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

message = deprecated_annotation.message
message = message ? " #{message}" : ""
check_deprecation(target_def, node, @deprecated_methods_detected)
end
end

full_message = node.warning "Deprecated #{short_reference}.#{message}"
private def check_deprecation(object, use_site, detects)
if (ann = object.annotation(self.deprecated_annotation)) &&
(deprecated_annotation = DeprecatedAnnotation.from(ann))
call_location = use_site.location.try(&.macro_location) || use_site.location
HertzDevil marked this conversation as resolved.
Show resolved Hide resolved
return if ignore_warning_due_to_location?(call_location)

self.warning_failures << full_message
# skip warning if the call site was already informed
# if there is no location information just inform it.
name = object.short_reference
warning_key = call_location.try { |l| "#{name} #{l}" }
return if !warning_key || detects.includes?(warning_key)
HertzDevil marked this conversation as resolved.
Show resolved Hide resolved
detects.add(warning_key) if warning_key

full_message = String.build do |io|
io << "Deprecated " << name << '.'
if message = deprecated_annotation.message
io << ' ' << message
end
end

@warning_failures << use_site.warning(full_message)
end
end

Expand Down