Several small refactors

This commit is contained in:
Sijawusz Pur Rahnama 2023-06-08 02:04:30 +02:00
parent 4d8346509e
commit 7caa47fb6a
2 changed files with 3 additions and 7 deletions

View file

@ -124,10 +124,7 @@ module Ameba::AST
# end
# ```
def spawn_block?
return false unless node.is_a?(Crystal::Block)
call = node.as(Crystal::Block).call
call.try(&.name) == "spawn"
node.as?(Crystal::Block).try(&.call).try(&.name) == "spawn"
end
# Returns `true` if current scope sits inside a macro.
@ -170,9 +167,7 @@ module Ameba::AST
# Returns `true` if current scope (or any of inner scopes) yields,
# `false` otherwise.
def yields?(check_inner_scopes = true)
return true if @yields
return inner_scopes.any?(&.yields?) if check_inner_scopes
false
@yields || (check_inner_scopes && inner_scopes.any?(&.yields?))
end
# Returns visibility of the current scope (could be inherited from the outer scope).

View file

@ -122,6 +122,7 @@ module Ameba::AST
@current_assign = node.value unless node.value.nil?
end
# :nodoc:
def end_visit(node : Crystal::TypeDeclaration)
return unless (var = node.var).is_a?(Crystal::Var)