Skip to content

Commit

Permalink
Improve error message when given location points to no macro
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust committed Dec 27, 2016
1 parent a2cb3b6 commit 5ee9205
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 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
@message = "no expansion found"
end

def process_type(type)
Expand Down Expand Up @@ -105,15 +106,31 @@ module Crystal
result.node.accept(self)

if @nodes.empty?
return ExpandResult.new("failed", "no expansion found")
return ExpandResult.new("failed", @message)
else
res = ExpandResult.new("ok", "#{@nodes.size} expansion#{@nodes.size > 1 ? "s" : ""} found")
res.expansions = @nodes.map { |node| ExpandTrace.build(node) }
return res
end
end

def visit(node : Call | MacroFor | MacroIf | MacroExpression)
def visit(node : Call)
if loc_start = node.location
loc_end = node.name_end_location
if @target_location.between?(loc_start, loc_end)
if node.expanded
@nodes << node
else
@message = "no expansion found: #{node} is not macro"
end
false
else
contains_target(node)
end
end
end

def visit(node : MacroFor | MacroIf | MacroExpression)
if loc_start = node.location
loc_end = node.end_location || loc_start
if @target_location.between?(loc_start, loc_end) && node.expanded
Expand Down

0 comments on commit 5ee9205

Please sign in to comment.