diff --git a/spec/compiler/crystal/tools/implementations_spec.cr b/spec/compiler/crystal/tools/implementations_spec.cr index 3f275c671101..fb6399cf3663 100644 --- a/spec/compiler/crystal/tools/implementations_spec.cr +++ b/spec/compiler/crystal/tools/implementations_spec.cr @@ -476,4 +476,18 @@ describe "implementations" do F‸oo ) end + + it "find implementation on def with no location" do + _, result = processed_implementation_visitor <<-CRYSTAL, Location.new(".", 5, 5) + enum Foo + FOO + end + + Foo.new(42) + CRYSTAL + + result.implementations.not_nil!.map do |e| + Location.new(e.filename, e.line, e.column).to_s + end.should eq [":0:0"] + end end diff --git a/src/compiler/crystal/tools/implementations.cr b/src/compiler/crystal/tools/implementations.cr index e2dbee001346..e4a6d210d922 100644 --- a/src/compiler/crystal/tools/implementations.cr +++ b/src/compiler/crystal/tools/implementations.cr @@ -53,7 +53,9 @@ module Crystal @line = macro_location.line_number + loc.line_number @column = loc.column_number else - raise "not implemented" + @line = loc.line_number + @column = loc.column_number + @filename = "" end end @@ -111,7 +113,7 @@ module Crystal if target_defs = node.target_defs target_defs.each do |target_def| - @locations << target_def.location.not_nil! + @locations << (target_def.location || Location.new(nil, 0, 0)) end end false