Skip to content

Commit

Permalink
Protect to visit method definitions too many time
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust committed Dec 27, 2016
1 parent 5ee9205 commit b1ada4d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/compiler/crystal/tools/expand.cr
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module Crystal
class ExpandVisitor < Visitor
def initialize(@target_location : Location)
@nodes = [] of ASTNode
@in_def_instance = false
@message = "no expansion found"
end

Expand All @@ -82,7 +83,9 @@ module Crystal
if type.is_a?(DefInstanceContainer)
type.def_instances.values.try do |typed_defs|
typed_defs.each do |typed_def|
@in_def_instance = true
typed_def.accept(self)
@in_def_instance = false
end
end
end
Expand All @@ -96,7 +99,9 @@ module Crystal

def process(result : Compiler::Result)
result.program.def_instances.each_value do |typed_def|
@in_def_instance = true
typed_def.accept(self)
@in_def_instance = false
end

result.program.types?.try &.values.each do |type|
Expand All @@ -114,8 +119,15 @@ module Crystal
end
end

def visit(node : Def | FunDef)
@in_def_instance && contains_target(node)
end

def visit(node : Call)
if loc_start = node.location
# If node.obj (a.k.a. an receiver) is a Path, it may be macro call and node.obj has no expansion surely.
# Otherwise, we cannot decide node.obj has no expansion.
loc_start = node.name_location unless node.obj.is_a?(Path)
loc_end = node.name_end_location
if @target_location.between?(loc_start, loc_end)
if node.expanded
Expand Down

0 comments on commit b1ada4d

Please sign in to comment.