Skip to content

Commit

Permalink
Fix: Current module not identified in defimpl (#665)
Browse files Browse the repository at this point in the history
Our defimpl resolver was not generating the current module name. It
was returning the same module as the protocol, which is incorrect
  • Loading branch information
scohen authored Mar 28, 2024
1 parent 5af876e commit 29f1055
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions apps/common/lib/lexical/ast/analysis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ defmodule Lexical.Ast.Analysis do
]} = quoted,
state
) do
module = protocol_segments
module = protocol_segments ++ for_segments
line = meta[:line]
current_module_alias = Alias.new(module, :__MODULE__, line)
for_alias = Alias.new(for_segments, :"@for", line)
protocol_alias = Alias.new(module, :"@protocol", line)
protocol_alias = Alias.new(protocol_segments, :"@protocol", line)

state
|> maybe_push_implicit_alias(protocol_segments, line)
Expand Down
26 changes: 21 additions & 5 deletions apps/remote_control/test/lexical/remote_control/analyzer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ defmodule Lexical.RemoteControl.AnalyzerTest do
test "works with @protocol in a protocol" do
{position, document} =
~q[
defimpl MyProtocol, for: Atom do
defimpl MyProtocol, for: Atom do
def pack(atom) do
|
def pack(atom) do
|
end
end
end
]
]
|> pop_cursor(as: :document)

analysis = Ast.analyze(document)
Expand All @@ -60,6 +60,22 @@ defmodule Lexical.RemoteControl.AnalyzerTest do
position
)
end

test "identifies the module in a protocol implementation" do
{position, document} =
~q[
defimpl MyProtocol, for: Atom do
def pack(atom) do
|
end
end
]
|> pop_cursor(as: :document)

analysis = Ast.analyze(document)
assert {:ok, MyProtocol.Atom} == Analyzer.current_module(analysis, position)
end
end

describe "reanalyze_to/2" do
Expand Down

0 comments on commit 29f1055

Please sign in to comment.