Skip to content

Commit 25ab648

Browse files
lukaszsamsonjosevalim
authored andcommitted
Fix autocomplete crash when expanding struct with __MODULE__ (#14308)
1 parent 8493f19 commit 25ab648

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/iex/lib/iex/autocomplete.ex

+5-3
Original file line numberDiff line numberDiff line change
@@ -378,16 +378,18 @@ defmodule IEx.Autocomplete do
378378
case Code.Fragment.container_cursor_to_quoted(code) do
379379
{:ok, quoted} ->
380380
case Macro.path(quoted, &match?({:__cursor__, _, []}, &1)) do
381-
[cursor, {:%{}, _, pairs}, {:%, _, [{:__aliases__, _, aliases}, _map]} | _] ->
381+
[cursor, {:%{}, _, pairs}, {:%, _, [{:__aliases__, _, aliases = [h | _]}, _map]} | _]
382+
when is_atom(h) ->
382383
container_context_struct(cursor, pairs, aliases, shell)
383384

384385
[
385386
cursor,
386387
pairs,
387388
{:|, _, _},
388389
{:%{}, _, _},
389-
{:%, _, [{:__aliases__, _, aliases}, _map]} | _
390-
] ->
390+
{:%, _, [{:__aliases__, _, aliases = [h | _]}, _map]} | _
391+
]
392+
when is_atom(h) ->
391393
container_context_struct(cursor, pairs, aliases, shell)
392394

393395
[cursor, pairs, {:|, _, [{variable, _, nil} | _]}, {:%{}, _, _} | _] ->

lib/iex/test/iex/autocomplete_test.exs

+3
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ defmodule IEx.AutocompleteTest do
416416
assert {:yes, ~c"ry: ", []} = expand(~c"%URI{path: \"foo\", que")
417417
assert {:no, [], []} = expand(~c"%URI{path: \"foo\", unkno")
418418
assert {:no, [], []} = expand(~c"%Unknown{path: \"foo\", unkno")
419+
420+
assert {:yes, [], _} = expand(~c"%__MODULE__{")
421+
assert {:yes, [], _} = expand(~c"%__MODULE__.Some{")
419422
end
420423

421424
test "completion for struct keys in update syntax" do

0 commit comments

Comments
 (0)